Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subclass UIApplication?

Tags:

iphone

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?

like image 448
masche Avatar asked Sep 09 '09 11:09

masche


People also ask

What is UIApplication in iOS?

The UIApplication encapsulates the central administrative properties of an application running on iOS. Application developers must not instantiate new UIApplications using constructors, but instead must use the static SharedApplication singleton property.

What is @UIApplicationMain?

UIApplicationMain(_:_:_:_:)Creates the application object and the application delegate and sets up the event cycle.


1 Answers

Did you pass the name of your subclass to UIApplicationMain? Let's assume you have

@interface MyUIApp : UIApplication 
...

then in main() you should do:

NSString* appClass = @"MyUIApp";
NSString* delegateClass = nil;
int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
like image 157
Teemu Kurppa Avatar answered Sep 21 '22 12:09

Teemu Kurppa