【问题标题】:iOS App keeps crashing when using an AdMob banneriOS 应用在使用 AdMob 横幅时不断崩溃
【发布时间】:2016-11-27 00:41:40
【问题描述】:

我正在使用 Xcode 7.3.1SpriteKitSwift 制作 iOS 8.0+ 游戏。每当我向其添加 AdMob 横幅时,我的应用程序就会不断崩溃。

我几乎从这里复制了横幅代码:https://firebase.google.com/docs/admob/ios/quick-start

这是我的代码的一部分:

class GameViewController: UIViewController, GADBannerViewDelegate{

  @IBOutlet var bannerView: GADBannerView!

  override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene(fileNamed:"GameScene") {

        let skView = self.view as! SKView

        skView.ignoresSiblingOrder = true


        scene.scaleMode = .AspectFill

        skView.presentScene(scene)

        let request = GADRequest()
        bannerView.delegate = self
        bannerView.adUnitID = "(myAppID)"
        bannerView.rootViewController = self
        bannerView.loadRequest(request)


    }
  }
 }

它在任何模拟器上都可以正常运行,但它会在实际设备上使应用程序崩溃。我不断收到此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'*** setObjectForKey: object cannot be nil (key: <f0cdd52e 01000000>)'
 *** First throw call stack: (0x1820b659c 0x19280c0e4 0x181fa11f8 0x1000ed1f8 0x100bbce30 0x100bbcdf0 0x100bc7854 0x100bc0120 0x100bc975c 0x100bcaf18 0x19302d2e4 0x19302cfa8)
libc++abi.dylib: terminating with uncaught exception of type NSException(lldb)

如果我删除处理横幅广告的部分代码,我的应用程序会完美运行。

关于我可以做些什么来解决它的任何建议?另外,这是我第一次使用 Xcode 编写应用程序。

谢谢!

【问题讨论】:

  • 不要将带有某个key的容器设置为nil,找到它崩溃的那一行,并修复它。例如。 dictionary["key"] = cheese where cheese = nil
  • @Knight0fDragon 这是否与 valueForKey 或类似的东西有关?
  • 不,您正在设置一个键,键的值正在读取。
  • 也许 myAppID 对你造成了影响
  • 那不应该是你的 appID,那应该是你的 google 广告 id

标签: ios swift xcode sprite-kit admob


【解决方案1】:

花了一段时间,但我想通了。我发现 Google 移动广告 SDK 框架是问题所在。版本 7.9.1 似乎不适用于 iOS 8.0,但在 iOS 9 上运行良好。我猜这就是它在我的设备上运行不佳的原因,因为我使用 SDK 7.9.1 运行 iOS 8。使用 7.8.0 等早期版本,广告可以轻松地在 iOS 8 设备上运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多