[英]Is anyone else having tons of issues when trying to add Admobs to their IOS project?
One of the many issues is when I try to add the func to show a Rewarded add:许多问题之一是当我尝试添加功能以显示奖励添加时:
func show() {
if let ad = rewardedAd {
ad.present(fromRootViewController: self) {
let reward = ad.adReward
print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
// TODO: Reward the user.
}
} else {
print("Ad wasn't ready")
}
}
This line throws an error: ad.present(fromRootViewController: self) { "Cannot convert value of type 'ContentView' to expected argument type 'UIViewController'此行引发错误:ad.present(fromRootViewController: self) { “无法将类型‘ContentView’的值转换为预期的参数类型‘UIViewController’
Another issue is the Google Utilities with the install Mobile ads SDK, a lot of items have been deprecated in IOS 12另一个问题是安装移动广告 SDK 的 Google Utilities,很多项目在 IOS 12 中已被弃用
Example: 'subscriberCellularProvider' is deprecated: first deprecated in IOS 12.0示例:'subscriberCellularProvider' 已弃用:首先在 IOS 12.0 中弃用
Has anyone successfully added admobs to an IOS app?有没有人成功将 admobs 添加到 IOS 应用程序? If you have any help would be nice, cause the documentation seems outdated.
如果您有任何帮助会很好,因为文档似乎已过时。
The Mobile Ads SDK (iOS) for Google AdMob tutorial适用于 Google AdMob 的移动广告 SDK (iOS) 教程
Admobs will ** NOT ** work outside of a view controller. Admobs 将**不会**在视图控制器之外工作。 Period.
时期。 Full stop.
句号。 I use Admob all the time and you must use it from within a view controller.
我一直使用 Admob,您必须在视图控制器中使用它。 It will not work any other way.
它不会以任何其他方式工作。
Try this:试试这个:
import UIKit
import GoogleMobileAds
class AdViewController: UIViewController, GADFullScreenContentDelegate {
private var rewardedInterstitialAd: GADRewardedInterstitialAd?
override func viewDidLoad() {
super.viewDidLoad()
GADRewardedInterstitialAd.load(withAdUnitID:"ca-app-pub-3940256099942544/6978759866",
request: GADRequest()) { ad, error in
if let error = error {
return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
}
self.rewardedInterstitialAd = ad
self.rewardedInterstitialAd?.fullScreenContentDelegate = self
}
}
/// Tells the delegate that the ad failed to present full screen content.
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
print("Ad did fail to present full screen content.")
}
/// Tells the delegate that the ad will present full screen content.
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad will present full screen content.")
}
/// Tells the delegate that the ad dismissed full screen content.
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad did dismiss full screen content.")
}
func show() {
guard let rewardedInterstitialAd = rewardedInterstitialAd else {
return print("Ad wasn't ready.")
}
rewardedInterstitialAd.present(fromRootViewController: self) {
let reward = rewardedInterstitialAd.adReward
// TODO: Reward the user!
}
}
func adDidDismissFullScreenContent() {
GADRewardedInterstitialAd.load(withAdUnitID:"ca-app-pub-3940256099942544/6978759866",
request: GADRequest()) { ad, error in
if let error = error {
return print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
}
self.rewardedInterstitialAd = ad
self.rewardedInterstitialAd?.fullScreenContentDelegate = self
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.