swift - Integration of adMob: Unexpectedly found nil while unwrapping an optional value -
i have switched on iad admob , having hard time integrating banner ads.
when run code, fatal error: unexpectedly found nil while unwrapping optional value
here code:
import googlemobileads class gameviewcontroller: uiviewcontroller, gadbannerviewdelegate { override func viewdidload() { super.viewdidload() let scene = gamescene(size: view.bounds.size) let skview = view as! skview skview.showsfps = false skview.showsnodecount = false skview.ignoressiblingorder = true scene.scalemode = .resizefill skview.presentscene(scene) print("google mobile ads sdk version: " + gadrequest.sdkversion()) var banner: gadbannerview! banner.delegate = self banner.adunitid = " ca-app-pub-xxxxxxxxxxx/xxxxxxxxxx" //crashing on line banner.loadrequest(gadrequest()) } }
i feel i've followed admob website, im having hard time figuring out error coming from. is/has else had problem?
you haven't initialized
banner
anywhere, should either create@iboutlet
if want create in interface builder, or initialize programmatically. why app crashes.var banner: gadbannerview! banner = gadbannerview(frame: self.view.frame) // initialized, fullscreen frame
the
adunitid
shouldn't start space.
Comments
Post a Comment