iPhone,如何避免看门狗因启动时间过长而杀死我的应用程序?
通知看门狗我没有处于无限循环并且我仍在加载所以不要杀死我的应用程序的正确方法是什么?
我在崩溃日志中收到 异常类型:00000020 异常代码:0x8badf00d 并且只有当独立于 xcode 从 iphone 运行应用程序时,
代码花费的时间是:
- (void)viewDidLoad {
[super viewDidLoad];
Reachability* reachability = [Reachability sharedReachability];
[reachability setHostName:@"www.apps2you.com"]; // set your host name here
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];
if (remoteHostStatus == ReachableViaWiFiNetwork||remoteHostStatus == ReachableViaCarrierDataNetwork )
{
//getting the xml file and then getting the ad images online to display as splah ads.
}
else {
//or launch the main interface if there's no connectivity.
[self DisplayTabbar];
}
}
谢谢。
what is the proper way to notify the watchdog that i'm not in an endless loop and that i'm still loading so don't kill my app?
I'm receiving in my crashlogs
Exception Type: 00000020
Exception Codes: 0x8badf00d
and only when running the app from iphone independently from xcode
the code taking time is :
- (void)viewDidLoad {
[super viewDidLoad];
Reachability* reachability = [Reachability sharedReachability];
[reachability setHostName:@"www.apps2you.com"]; // set your host name here
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];
if (remoteHostStatus == ReachableViaWiFiNetwork||remoteHostStatus == ReachableViaCarrierDataNetwork )
{
//getting the xml file and then getting the ad images online to display as splah ads.
}
else {
//or launch the main interface if there's no connectivity.
[self DisplayTabbar];
}
}
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一些初始化需要很长时间,那么最好在新线程中运行它(通过
performSelectorInBackground:withObject:
)。然后,您的 UI 将以某种“锁定”状态启动。创建一个“解锁”UI 的方法。作为后台方法的最后一个操作,通过performSelectorOnMainThread:withObject:waitUntilDone:
运行该解锁方法。重要的是不要阻塞主线程,以便运行循环可以响应 iOS 事件。这就是为什么你应该避免睡眠或其他阻塞的东西。不过,阻塞另一个线程是可以的。此外,采用基于事件的编程方法也有很大帮助。
更新:
现在,最好使用
dispatch_async
而不是performSelectorInBackground:withObject:
。您仍然应该在dispatch_async
块内创建一个新的NSAutoreleasePool
以避免内存泄漏。If you have some initializing that takes a long time then it's best to run it in a new thread (via
performSelectorInBackground:withObject:
). Your UI would then start in some "locked" state. Create a method that "unlocks" the UI. As the very last action of your background method, run that unlock method viaperformSelectorOnMainThread:withObject:waitUntilDone:
.It's important not to block the main thread so that the run loop can respond to iOS events. That's why you should avoid
sleep
or other blocking stuff. It's alright to block in another thread, though. Also, adapting event-based programming methods help a lot.Update:
Nowadays, it's better to use
dispatch_async
instead ofperformSelectorInBackground:withObject:
. You still should create a newNSAutoreleasePool
inside thedispatch_async
block to avoid memory leaks.我认为如果看门狗正在杀死您的应用程序,那么加载时间就会太长,并且您的用户不会等待它。查看一些内存管理技术,您可能需要更好地构建您的项目。
可能有一种方法可以告诉看门狗不要杀死您的应用程序,但我保证您的加载时间会让您的用户感到沮丧,并且您的应用程序将无法获得您想要的外展。
I think if watchdog is killing your app, then it takes way too long to load and your users wont wait for it. Look at some memory management techniques and you may have to structure your project better.
There may be a way to tell watchdog not to kill your app, but I guarantee your load times will frustrate your users and you won't be getting the out-reach you want with your app.