iOS and SDL Admob support


#1

I have been at work on a puzzle game which supports Android and iOS platforms. I wanted to include advertisements through Admob to help monetize the game while it is getting past the beta stage. So far I’ve succeeded in supporting Admob on Android; iOS is posing more difficulty.

The main problem I’m facing is displaying a custom (i.e. banner advertisement) UIView overlaying the main SDL window. I am quite new to Objective C as well as UIKit development, I guess what I’m not understanding is how the SDL Objective C code shares the screen with the system.

A basic run-down of the calls I’m making so far (btw this is all coded from the imported SDL project, I’m not proficient enough with ObC yet to subclass and instantiate my own objects):

  • in SDL_uikitappdelegate.m/h:
    call [GADMobileAds configureWithApplicationID:@“APP_ID”]; in didFinishLaunchingWithOptions
    import “GoogleMobileAds/GoogleMobileAds.h” in the header (currently not needed).

  • in SDL_uikitviewcontroller.m: override
    “- (void)viewDidLoad” to create a custom UIView:
    CGRect viewRect = CGRectMake(0, 0, 200, 200);
    UIView *uiview = [[UIView alloc] initWithFrame : viewRect];
    uiview.backgroundColor = [UIColor whiteColor];
    and then I’m at a complete loss as to how I share it on the screen with SDL. I’ve attempted exploring the structure of “SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;”, but without any visible results.

I’ve searched for hours on Google without a complete clue, can someone please explain?

The project I’m describing is called ‘Platonic Opaline’, it’s available on Google Play:


and on App Store:


#2

Firstly, I’d avoid modifying the SDL source code. What will you do when a new version of SDL comes out?

Secondly, you should be able to access the actual UIWindow that your game is using by the SDL_GetWindowWMInfo() function and then accessing its uikit.window element. From there you can mess with the view heirarchy. Just be aware that putting a view over the top of the view SDL is using can hurt performance, since you’re forcing iOS to use the window compositor instead of pushing the game window directly to the screen.