Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Extending the UIApplicationDelegate
- - By jlnr (dev) Date 2010-08-28 03:18
There are times when you want to override methods in the UIApplicationDelegate. However, Gosu needs its own delegate for a few methods (didInitialize mostly), so you cannot set the delegate to your own instance. What you can do, however, is simply using Objective C categories to just attach methods to Gosu's implementation:


// Make GosuAppDelegate known
@interface GosuAppDelegate
@end

// Add a category to GosuAppDelegate
@interface GosuAppDelegate (YourExtension)
@end

// Now add new methods
@implementation GosuAppDelegate (YourExtension)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)newURL
{
...
}
...
@end
Parent - - By erisdiscord Date 2010-08-28 18:47
This is why I (kind of) love Objective-C. :)

One thing: I'd recommend publishing a list of delegate methods that your delegate implements so we, the unwitting users of your library don't accidentally trample them and wonder what's going on when something weird breaks.
Parent - By jlnr (dev) Date 2010-08-28 21:10
Good idea:


// All three empty, but SDK docs say these are "required" (?)
- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application;
- (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application;
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification:
// Sets up everything
- (void)applicationDidFinishLaunching:(UIApplication *)application;
// Stops/resumes Song
- (void)applicationWillResignActive:(UIApplication *)application;
- (void)applicationDidBecomeActive:(UIApplication *)application;


Gosu basically forwards applicationWillResignActive as the "Window::loseFocus" callback now. It could do the same for ~BecomeActive.

The didReceiveLocalNotification sounds a bit like a pity.
Up Topic Gosu / Gosu on iPad, iPhone & iPod Touch / Extending the UIApplicationDelegate

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill