AdMob implementations for SwiftUI
SwiftUI_AdMob
AdMob implementations for SwiftUI
Ads
Currently this repo contains:
RewardedAds
Usage in SwiftUI:
init(){
self.rewardAd = RewardedAd()
rewardAd.load()
}
var body: some View {
self.rewardAd.showAd(rewardFunction: {
// TODO
}
}
BannerAds
Usage in SwiftUI:
BannerAd()
How to integrate this into your own project
- Add the AdMob SDK to your
Podfile
, you can copy thePodfile
of this project - Install the pods and update your
info.plsit
and add your own Ad ID. Check out the official AdMob documentation for an example - Copy the ad file from this repository into your own project and replace the AdIds
- Initialize the Ad framework in your app file
- Add the Ads in your SwiftUI code and you are ready to go
Troubleshooting
I sometime run into very strange and unexpected errors when I integrate AdMob into my app, which is why I usually add it when the project is nearly finished. If you run into some issues, a lot of times I just run pod install --repo-update
again, which solves most of the problems.
You can also check out my Medium Article for more help on how to set up AdMob in XCode 13.