We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3377

Summary: IOS crashes with AdMob framework 7.8.1
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: videoAssignee: Alex Szpakowski <amaranth72>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72, phil
Version: don't know   
Hardware: iPhone/iPod touch   
OS: iOS (All)   

Description Sylvain 2016-06-24 16:26:23 UTC
Linking with AdMob 7.8.1 framework, and calling "@import GoogleMobileAds" makes my app crash, with the following message:

*** Terminationg app due to uncaught exception 'NSInvalidArgumentException', reason '- [MyApp_UIKitDelegate window]: unrecognized selector sent to instance of 0x7ff9987098f0]'

AdMob framework can be downloaded there: https://firebase.google.com/docs/admob/ios/download


It looks like the issue is with the SDL framework itself. The UIApplicationDelegate method is not properly implement, especially the declaration of the UIWindow property. One quick way to solve the issue would be to:

In SDLUIKitDelegate class: 

@interface SDLUIKitDelegate : NSObject<UIApplicationDelegate>

+ (id)sharedAppDelegate;
+ (NSString *)getAppDelegateClassName;
@property(nonatomic, strong) UIWindow *window; //<<<<<<< This property is missing. Simply add this and it builds.


By adding the UIWindow property, even though it works, might not be an effective solution. 
It looks like the UIWindow is declared separately in header file, which is not necessary as the UIApplicationDelegate already implements the project's UIWindow.
Comment 2 Alex Szpakowski 2016-06-24 19:30:02 UTC
The apple docs say: "Implementation of this property is required if your app’s Info.plist file contains the UIMainStoryboardFile key. "

(In other words it's only required if you use a Storyboard for setting up the main UI, which SDL doesn't do).

I'll look into this further and if the workaround doesn't cause any problems then I'll probably implement it, but it seems like it's probably actually a bug in Admob that it doesn't check if [appdelegate window] exists before trying to call it, since iOS doesn't mandate its presence.
Comment 3 Sylvain 2016-06-24 19:50:49 UTC
I agree it seems optional indeed. It's technically possible not to use the internal window property. But this seems also the way apple recommend to use it.

And this is how Google's Mobile Ads SDK is built, as it expects that the keyWindow is the one implemented by UIApplicationDelegate.
Comment 4 Alex Szpakowski 2016-06-24 20:01:59 UTC
Right, and that's a bug in Admob. But it soumds like we can work around their bug (provided that implementing our own [AppDelegate window] doesn't do anything unexpected inside iOS – which wouldn't surprise me.)
Comment 5 philhassey 2016-12-02 21:28:36 UTC
I've also come across this issue while using some other ad networks.  I also added this to SDL_uikitwindow.m

in

static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)

    data.uiwindow = uiwindow;
+    [UIApplication sharedApplication].delegate.window = uiwindow;

This makes sure the property is set.

Thanks!
-Phil
Comment 6 Alex Szpakowski 2016-12-18 16:29:44 UTC
I committed a workaround to avoid the bugs in those third-party libraries: https://hg.libsdl.org/SDL/rev/5c8870c092ed

However it hasn't been tested very thoroughly, so let me know if it works!