iOS App keeps crashing when using an AdMob banner - ios

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.

Related

App crash when MFMessageComposeViewController is initialisation

I want to send a message through my app. I call the following method on click
#IBAction func sendMessage(_ sender: Any) {
if (MFMessageComposeViewController.canSendText()) {
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
// Configure the fields of the interface.
composeVC.recipients = ["4085551212"]
composeVC.body = "Hello from California!"
// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)
}
}
The problem is if I run the app on device, it crashes at MFMessageComposeViewController initialisation i.e.
let composeVC = MFMessageComposeViewController()
If I run the app in simulator, it crashes on presentation i.e.
self.present(composeVC, animated: true, completion: nil)
Error log when I run the app on device
2018-01-29 12:03:57.826816+0530 EWS[2495:806400] *** Assertion failure in -[UICGColor encodeWithCoder:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.33.7/UIColor.m:1722
2018-01-29 12:03:57.827522+0530 EWS[2495:806400] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
*** First throw call stack:
(0x183702364 0x182948528 0x183702238 0x18409d7f4 0x18d08fffc 0x1840574dc 0x18405e8d8 0x18d4ebf20 0x18d4eb74c 0x18d4e7044 0x1835d03c0 0x18d4e6d44 0x18d7f16fc 0x18d60bd18 0x18d60b94c 0x19aee4534 0x19aecbff4 0x19aecc314 0x1984ce830 0x101159ec0 0x101158888 0x1011584b4 0x1011589c0 0x18cc186b4 0x18cc18634 0x18cc031dc 0x18cc17f28 0x18cc17a48 0x18cc12f60 0x18cbe3f64 0x18d53931c 0x18d53b8a8 0x18d5347c0 0x1836aa97c 0x1836aa8fc 0x1836aa184 0x1836a7d5c 0x1835c7e58 0x185474f84 0x18cc4767c 0x101157170 0x1830e456c)
libc++abi.dylib: terminating with uncaught exception of type NSException
Error log when I run the app on simulator (without checking if(MFMessageComposeViewController.canSendText()))
2018-01-29 12:07:49.395714+0530 EWS[3533:67163] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <EWS.BlockVC: 0x7f899c61db10>.'
*** First throw call stack:
Any help would be appreciated.
Okay,
When you run it in iPhone : The crash log clearly states that "Only RGBA or White color spaces are supported in this situation." So by hint I would say you are assigning color somewhere, (Some Global tint, navigation bar tint) , which doesn't apply to a MFMessageComposeViewController, hence its crashing.
When you run it in the simulator :
if (MFMessageComposeViewController.canSendText()), this line will prevent it from initialising the MFMessageComposeViewController, in the simulator as it cant send text, hence when you try to present it, its not yet initialised and crashing.
On a second thought, as per your code : self.presentViewController(composeVC, animated: true, completion: nil), this line should not even be called while running in the simulator as this line is inside the if statement, which wont get through.
Also change the tint color or any while initialising the controller, and tell me what the results are.

AdMob Banner in ShareSheet

Is there any restriction that it is not possible to display a bannerview from Google Admob in a sharesheet? I have an app which provides additional data in the sharesheet, and I also want to display ads there. In my main app, the ads work fine - but in the sharesheet, I don't get any error message or anything when initialising the ads.
Greetings,
Jack
Update: I am using the cocoapod Firebase/Admob. This one is assigned to the main app and the sharesheet. As I have the ads on several view controlers, I created a function, which is connected via an app group to both parts. In ViewDidLoad, I initialice google admob
GADMobileAds.configure(withApplicationID: "filledwiththecorrectcode")
Then I run this function providing the view and the constrains:
func loadAdd(ViewController: GADBannerView, HightConstrain: NSLayoutConstraint, MainApp: Bool){
ViewController.adSize = kGADAdSizeSmartBannerPortrait
// TEST CODE
ViewController.adUnitID = "ca-app-pub-3940256099942544/2934735716"
ViewController.rootViewController = self
HightConstrain.constant = 50
let request: GADRequest = GADRequest()
request.testDevices = [kGADSimulatorID]
ViewController.load(request)
}
}
This works fine in the main app. In the sharesheet, I run the same function - it also walks through in the debugger, but nothing happens. Ah, the

Admob iOS test ads in release build

I have the next issue with admob. I created app for iOS 8 in swift using the latest admob sdk and I when I debug this app on the simulator I see test ads, when I debug on the real device I see the real ads. But when I published the app to the app store I see test ads.
I have not set up any test ads on the device or in the account adb it must show ads in simulator only, but I see test ads in release build on the AppStore.
Maybe I doing something wrong? I have not requested testing on any device so it must show me real ads on any real device but it does not.
My code
override func viewDidLoad() {
super.viewDidLoad()
self.bannerView.adUnitID = "my id"
self.bannerView.rootViewController = self
var request:GADRequest = GADRequest()
self.bannerView.loadRequest(request)
//other setup code which is not related to ads
let tracker = GAI.sharedInstance().defaultTracker
let build = GAIDictionaryBuilder.createAppView().set("Custom event", forKey: kGAIScreenName).build() as NSDictionary
tracker.send(build as [NSObject : AnyObject])
}
Other controller
override func viewDidLoad() {
super.viewDidLoad()
var interstitial : GADInterstitial = GADInterstitial()
interstitial.adUnitID = "interstitial ad id"
var request: GADRequest = GADRequest()
interstitial.loadRequest(request)
//other setup code not related to ads
}
I was provided by wrong advertiser id. So fix is obvious - just recheck your ad unit id before release.

App crashes when trying to resign keyboard

Since I updated to the latest Xcode 6 beta, I have been having issues with closing the keyboard. My app is crashing each time I try to close the keyboard, even though I have used the same code for ages and it used to work fine.
Here is what I have:
#IBAction func viewTapped(sender : AnyObject) {
//Closes keyboard when user touches screen.
transactionDateInput.resignFirstResponder()
transactionNameInput.resignFirstResponder()
textField.resignFirstResponder()
notesField.resignFirstResponder()
UIView.animateWithDuration(1.5, animations: {
self.valueEnter.alpha = 0
self.dateEnter.alpha = 0
self.notesDone.alpha = 0
})
}
Someone suggested changing it to something like this:
if (transactionDateInput.isFirstResponder() == true){
transactionDateInput.resignFirstResponder()
}
but that makes no difference. Anyone have any suggestions? Here is the error:
AffordIt[4445:1334424] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AffordIt.SecondViewController textFieldShouldReturn:]: unrecognized selector sent to instance 0x7fb169666880'
Check your Text Field outlet delegate (right click to Text Field)
there should be delegate to your UIViewController!
Look at this tutorial

Mapbox NSInternalInconsistencyException showing RMMapView on iPad

Having a spot of trouble trying to get the native iOS Mapbox view working on an actual device (3rd gen iPad, iOS 7.1).
dprintf( "RMMapboxSource\n" );
RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:mystyle];
dprintf( "RMMapView\n" );
RMMapView * mapView = [[RMMapView alloc] initWithFrame:CGRectMake(0,0,900,450) andTilesource:tileSource];
dprintf( "addChild\n" );
// ... mapView then added to view hierarchy
dprintf( "setPage\n" );
// ... then make visible
Everything works great in the simulator. But trying to run on an actual iPad results in the following.
RMMapboxSource
RMMapView
addChild
setPage
2014-04-01 15:41:21.879 Protraak[1179:60b] *** Assertion failure in -[UIView layoutSubviews], /SourceCache/UIKit/UIKit-2935.137/UIView.m:5326
2014-04-01 15:41:21.881 Protraak[1179:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout should have been successfully accomplished'
A Google search for "layout should have been successfully accomplished" came up blank.
Can you try the latest develop branch and see if that works for you?

Resources