Commit 5e1ffb1c authored by Sam Lantinga's avatar Sam Lantinga

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!
parent 0e83d1d4
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
} }
+(SDLUIKitDelegate *)sharedAppDelegate; +(SDLUIKitDelegate *)sharedAppDelegate;
+(NSString *)getAppDelegateClassName;
@end @end
/* *INDENT-ON* */ /* *INDENT-ON* */
......
...@@ -50,7 +50,7 @@ int main(int argc, char **argv) { ...@@ -50,7 +50,7 @@ int main(int argc, char **argv) {
forward_argv[i] = NULL; forward_argv[i] = NULL;
/* Give over control to run loop, SDLUIKitDelegate will handle most things from here */ /* 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]; [pool release];
return 0; return 0;
...@@ -64,6 +64,12 @@ int main(int argc, char **argv) { ...@@ -64,6 +64,12 @@ int main(int argc, char **argv) {
return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate]; 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 { - (id)init {
self = [super init]; self = [super init];
return self; return self;
...@@ -90,8 +96,7 @@ int main(int argc, char **argv) { ...@@ -90,8 +96,7 @@ int main(int argc, char **argv) {
/* Set working directory to resource path */ /* Set working directory to resource path */
[[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
[self performSelector:@selector(postFinishLaunch) withObject:nil [self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
afterDelay:0.0];
return YES; return YES;
} }
...@@ -113,7 +118,7 @@ afterDelay:0.0]; ...@@ -113,7 +118,7 @@ afterDelay:0.0];
return; return;
} }
SDL_Window *window; SDL_Window *window;
for (window = _this->windows; window != nil; window = window->next) { for (window = _this->windows; window != nil; window = window->next) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment