patrickhaertel / swiftuimobileads Goto Github PK
View Code? Open in Web Editor NEWSwiftUIMobileAds allows you to integrate v8 of the Google Mobile Ads SDK into your SwiftUI app.
License: MIT License
SwiftUIMobileAds allows you to integrate v8 of the Google Mobile Ads SDK into your SwiftUI app.
License: MIT License
Hi there,
Just added the functionality to my App, the only thing is that it appears like the Reward Ad won't show up when using:
func makeUIViewController(context: Context) -> UIViewController
{
let view = UIViewController()
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1)) {
self.showAd(from: view)
}
return view
}
Change this code to:
func makeUIViewController(context: Context) -> UIViewController
{
let view = UIViewController()
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1)) {
self.showAd(from: (UIApplication.shared.windows.first?.rootViewController)!)
}
return view
}
Thanks for taking the time on doing this project about Google Ads on SwiftUI!
Please add
<key>NSUserTrackingUsageDescription</key>
<string>SwiftUIMobileAds will never track you. The NSA, however...</string>
to Info.plist
dyld: Library not loaded: @rpath/FBLPromises.framework/FBLPromises
First, thanks for this code. It's great and has been a great help.
In new releases there's a new warning in the build:
func setFrame() {
This line has this warning: 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead:
let safeAreaInsets = UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.safeAreaInsets ?? .zero
let frame = UIScreen.main.bounds.inset(by: safeAreaInsets)
let adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.width)
self.width = adSize.size.width
self.height = adSize.size.height
}
After a lot of research I didn't find a clear answer. I fixed it with:
func getSafeArea()-> UIEdgeInsets {
let keyWindow = UIApplication
.shared
.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.first { $0.isKeyWindow }
return (keyWindow?.safeAreaInsets)!
}
func setFrame() {
let safeAreaInsets = getSafeArea()
let frame = UIScreen.main.bounds.inset(by: safeAreaInsets)
let adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.width)
self.width = adSize.size.width
self.height = adSize.size.height
}
This fixes the warning and seems to mostly work, but I get a few crashes in getSafeArea() with an unwrapped nil error. I can see why that would be, but since you actually know what you're doing, I'm just wondering if there's a better fix?
thanks
Since iOS 16, UIViewControllerRepresentable instances can only be structs. Change all three UIViewControllerRepresentable (BannerAd, RewardedAdView, InterstitialAdView) views into a struct.
Hi and thank you for your great work and tutorial!
I wanted to ask if there is any possibility you will also demonstrate how to implement other ads libs such as IronSource or AppLovin with swiftUI?
since there is no documentation nor other tutorials on the web at all on how to integrate those libs with swiftui, only with old swift which is completely different implementation and off course doesn't work :
thanks again for your work!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.