Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Allow overriding the app delegate on iOS
Browse files Browse the repository at this point in the history
Vittorio G.  to Eric, Sam

Actually this is much simpler than i thought, I just had to specify a
class method to get the delegate name and then the category can
override that method!
I've attached the patch that enables this features: in my code i could
remove my custom main() and simply add

@implementation SDLUIKitDelegate (customDelegate)
+(NSString *)getAppDelegateClassName {
   return @"HedgewarsAppDelegate";
}
@EnD

I tested it and with the sdl demos it loads the normal
SDLUIKitDelegate, while in my code it loads my HedgewarsAppDelegate!
  • Loading branch information
slouken committed Apr 5, 2011
1 parent 81160d6 commit 905d5ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitappdelegate.h
Expand Up @@ -28,6 +28,7 @@
}

+(SDLUIKitDelegate *)sharedAppDelegate;
+(NSString *)getAppDelegateClassName;

@end
/* *INDENT-ON* */
Expand Down
13 changes: 9 additions & 4 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char **argv) {
forward_argv[i] = NULL;

/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
UIApplicationMain(argc, argv, NULL, @"SDLUIKitDelegate");
UIApplicationMain(argc, argv, NULL, [SDLUIKitDelegate getAppDelegateClassName]);

[pool release];
return 0;
Expand All @@ -64,6 +64,12 @@ +(SDLUIKitDelegate *)sharedAppDelegate {
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
}

+(NSString *)getAppDelegateClassName {
/* subclassing notice: when you subclass this appdelegate, make sure to add a category to override
this method and return the actual name of the delegate */
return @"SDLUIKitDelegate";
}

- (id)init {
self = [super init];
return self;
Expand All @@ -90,8 +96,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
/* Set working directory to resource path */
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];

[self performSelector:@selector(postFinishLaunch) withObject:nil
afterDelay:0.0];
[self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];

return YES;
}
Expand All @@ -113,7 +118,7 @@ - (void) applicationWillResignActive:(UIApplication*)application
return;
}

SDL_Window *window;
SDL_Window *window;
for (window = _this->windows; window != nil; window = window->next) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
}
Expand Down

0 comments on commit 905d5ff

Please sign in to comment.