简体   繁体   English

在尝试将 Admobs 添加到他们的 IOS 项目时,是否还有其他人遇到过很多问题?

[英]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.

相关问题 编译xcode项目时Alamofire存在大量问题 - Tons of issues with Alamofire when compiling xcode project 其他人在使用iOS 5加密时遇到问题? - Anyone else having trouble with iOS 5 encryption? 其他人在iOS中有配置文件问题吗? - Anyone else having Provisioning Profile Problems in iOS? 尝试将ios添加到项目时出现离子错误 - Ionic error when trying to add ios to project 其他人在使用Podio iOS应用和Google街景时遇到问题? - Anyone else having trouble with Podio iOS app and Google Street View? iOS快速与Facebook集成项目:大量警告 - IOS swift project integration with Facebook : tons of warnings 是否有人难以让ZBar在他们的iOS8 / Xcode项目中工作? - Is anyone having difficulty with getting ZBar to work in their iOS8 / Xcode project? 尝试添加ios平台项目时出现Ionic Framwork错误 - Ionic Framwork error when trying to add ios platform project 还有其他人无法将XCode更新到4.3.1吗? - Anyone else having trouble updating XCode to 4.3.1? 将cordova添加到我现有的ios项目时的问题:cordovaSettingForKey:]:发送到实例的无法识别的选择器 - Issues when add cordova to my existing ios project: cordovaSettingForKey:]: unrecognized selector sent to instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM