开发者

iOS - How can I create and destroy serial instances of UIApplication?

开发者 https://www.devze.com 2023-02-01 07:02 出处:网络
This may be of little use to anyone, but it\'s possible to return from UIApplicationMain by nesting the call in a try{}catch(NSException* e){} block. I\'m currently doing this for testing my setup pro

This may be of little use to anyone, but it's possible to return from UIApplicationMain by nesting the call in a try{}catch(NSException* e){} block. I'm currently doing this for testing my setup process, in order to run some logic after the application ex开发者_JS百科its. I'd like to take this a step further and actually write separate UIApplication sub classes and run them in serial but UIApplicationMain doesn't want to play nice, it's a singleton and it must remember what it once was (the first UIApplication to be instantiated). Here's the error I get when I attempt to create a second UIApplication after returning from the first call to UIApplicationMain...

2010-12-28 16:01:36.890 SomeFakeAppName[26993:207] *** Assertion failure in UIApplicationInstantiateSingleton(), /SourceCache/UIKit_Sim/UIKit-1447.6.4/UIApplication.m:1263

So, two questions:

I understand that I'm probably 'Doing It Wrong' but how might I go about clearing UIApplication's memory so that it thinks each successive UIApplication instantiation is its first?

If this is a dead end I may try replacing UIApplicationMain by manually setting up the main event loop and instantiating the UIApplication, has anyone done this?


Pretty sure you can't. UIApplication's are managed on the OS level and Apple doesn't really give you the keys to drive how all that works.

If it's possible at all, you would be diving into private APIs (which shouldn't be a problem cause we are talking about non-released test suite setup right?). Look up the UIApplication.h decompiled header files that are in a few various places. Look for private methods that sounds like what you want and try it out.

But in all likelihood, this path leads leads to pain and suffering.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号