【发布时间】:2016-11-27 00:41:40
【问题描述】:
我正在使用 Xcode 7.3.1、SpriteKit 和 Swift 制作 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