tags:

views:

761

answers:

2

The iPhone Reference Libary - UIApplication says I can subclass UIApplication, but if I try this I will get an exception:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIApplication instance.'

This reminds me of the Highlander "There can be only one,. :-)

Do I have to pass other argurments to UIApplicationMain? Or did I missread somthing in the libary?

+2  A: 

In your app's info.plist, make sure you change the NSPrincipalClass key to the name of your subclass. This'll make Cocoa instantiate the correct class when the applications loads - you shouldn't have to do anything other than that to get your subclass working.

iKenndac
There is no NSPrincipalClass key in my info.plist. Should i add it?
Markus Scheucher
Yes - there are many, many keys that could be in your Info.plist - they aren't all included by default.
iKenndac
This seems Mac OS X only, not for iPhone OS: http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW1
Eonil
+3  A: 

Did you pass name of your subclass to UIApplicationMain? assume you have

@interface MyUIApp : UIApplication 
...

and then in main():

NSString* appClass = @"MyUIApp";
NSString* delegateClass = nil;
int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
tequilatango
Hi, I have tried the same way as suggested in answer... but i'm still getting the same error... Anything else i need to do...?
mihirpmehta