[Commits] SDL: Allow overriding the app delegate on iOS

libsdl.org revision control commits-owner at libsdl.org
Tue Apr 5 09:51:58 PDT 2011


details:   http://hg.libsdl.org/SDL/rev/8a04b596b472
changeset: 5532:8a04b596b472
user:      Sam Lantinga <slouken at libsdl.org>
date:      Tue Apr 05 09:50:25 2011 -0700
description:
Allow overriding the app delegate on iOS

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!

diffstat:

 src/video/uikit/SDL_uikitappdelegate.h |   1 +
 src/video/uikit/SDL_uikitappdelegate.m |  13 +++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diffs (55 lines):

diff -r 477f550f6efd -r 8a04b596b472 src/video/uikit/SDL_uikitappdelegate.h
--- a/src/video/uikit/SDL_uikitappdelegate.h	Tue Apr 05 09:47:34 2011 -0700
+++ b/src/video/uikit/SDL_uikitappdelegate.h	Tue Apr 05 09:50:25 2011 -0700
@@ -28,6 +28,7 @@
 }
 
 +(SDLUIKitDelegate *)sharedAppDelegate;
++(NSString *)getAppDelegateClassName;
 
 @end
 /* *INDENT-ON* */
diff -r 477f550f6efd -r 8a04b596b472 src/video/uikit/SDL_uikitappdelegate.m
--- a/src/video/uikit/SDL_uikitappdelegate.m	Tue Apr 05 09:47:34 2011 -0700
+++ b/src/video/uikit/SDL_uikitappdelegate.m	Tue Apr 05 09:50:25 2011 -0700
@@ -50,7 +50,7 @@
     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;
@@ -64,6 +64,12 @@
     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;
@@ -90,8 +96,7 @@
     /* 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;
 }
@@ -113,7 +118,7 @@
         return;
     }
 	
-	SDL_Window *window;
+    SDL_Window *window;
     for (window = _this->windows; window != nil; window = window->next) {
         SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
     }


More information about the commits mailing list