简体   繁体   中英

iOS App keeps crashing when using an AdMob banner

I'm making an iOS 8.0+ game using Xcode 7.3.1 , SpriteKit , and Swift . My app keeps on crashing whenever I add the AdMob banner to it.

I've pretty much copied the banner code from here: https://firebase.google.com/docs/admob/ios/quick-start

Here's a part of my code:

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)


    }
  }
 }

It runs perfectly fine on any simulator, but it crashes the app on an actual device. I keep getting this error:

*** 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)

If I remove part of the code that deals with the banner ad, my app runs perfectly.

Any suggestions on what I can do to fix it? Also, this is my first time coding an app using Xcode.

Thanks!

It took a while, but I figured it out. I found out that the Google Mobile Ads SDK framework was the problem. Version 7.9.1 doesn't seem to work on iOS 8.0, but works well on iOS 9. I'm guessing that's why it didn't run well on my device, since I was running iOS 8 with SDK 7.9.1. With earlier versions such as 7.8.0, ads can run easily on iOS 8 devices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM