1. ios7系统中, 如果应用进入后台时,它并没有彻底进入后台, 而是有默认的10秒运行时间,
代码如下, 把下面这部分代码放入在ios中, 点击某个按钮来调用, 然后按Home键进入后台, 观察log输出情况, (注:需要在release版下观察, debug版下程序不会停止,即使剩余时间为0也会继续运行。)
下面的代码会输出程序进入后台前的剩余时间长度
- (void)printLogs {
while (1) {
NSLog(@"hello, world, last time=%f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
sleep(1);
}
}
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
#define NABStartBackgroundTask() NSLog(@"NABStartBackgroundTask");\
UIBackgroundTaskIdentifier taskID = UIBackgroundTaskInvalid; \
taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ \
NSLog(@"Expirationed Handler invoked.");\
[[UIApplication sharedApplication] endBackgroundTask:taskID]; }];
#define NABEndBackgroundTask() NSLog(@"NABEndBackgroundTask");\
[[UIApplication sharedApplication] endBackgroundTask:taskID];
#else
#define NABStartBackgroundTask()
#define NABEndBackgroundTask()
#endif
{(
<BKProcessAssertion: 0x17697d30> identifier: Suspending process: UOgfd[831] permittedBackgroundDuration: 10.000000 reason: suspend owner pid:28 preventSuspend preventThrottleDownCPU preventThrottleDownUI preventSuspendOnSleep
)}
Sep 2 17:37:38 Red5c backboardd[28] <Warning>: Forcing crash report of UOgfd[831]...
Sep 2 17:37:38 Red5c backboardd[28] <Warning>: Finished crash reporting.
Sep 2 17:37:38 Red5c com.apple.launchd[1] (UIKitApplication:com.baidu.UOgfd[0x5df4][831]) <Notice>: (UIKitApplication:com.baidu.UOgfd[0x5df4]) Exited: Killed: 9
Sep 2 17:37:38 Red5c backboardd[28] <Warning>: Application 'UIKitApplication:com.baidu.UOgfd[0x5df4]' exited abnormally with signal 9: Killed: 9