Run task when app enter background.
2012-02-24 13:38
225 查看
1. Add the
2.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [[UIDevice currentDevice] isMultitaskingSupported])
{
NSLog(@"Keep timeout alive");
[application setKeepAliveTimeout:600 handler: ^{
NSLog(@"applicationDidEnterBackground:: setKeepAliveTimeout:handler^");//task as you want to do
}];
}
#else
LogInfo(@"applicationDidEnterBackground (Not supported)");
#endif
}
UIBackgroundModeskey to your application’s
Info.plistfile. Set the value of this key to an array that includes the
voipstring.
2.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [[UIDevice currentDevice] isMultitaskingSupported])
{
NSLog(@"Keep timeout alive");
[application setKeepAliveTimeout:600 handler: ^{
NSLog(@"applicationDidEnterBackground:: setKeepAliveTimeout:handler^");//task as you want to do
}];
}
#else
LogInfo(@"applicationDidEnterBackground (Not supported)");
#endif
}
相关文章推荐
- iOS XMPP App run background (by voip)
- iOS提交审核:“your app did not run at iPhone resolution when reviewed on iPad run iOS 10.1.1”
- Android Studio2.1 Run APP:Error: Execution failed for task
- c# task run in background
- APP Run In Background(App 的后台运行)
- Hide C# winform App Window When Started by Task Scheduler
- Error:Execution failed for task ':app:transformClassesWithInstantRunForFlavors_devDev'. > JSR/RET ar
- Upload large file in background (service restarting when the app closed)
- Android异常之Error:Execution failed for task ':app:transformClassesWithInstantRunSlicerForDebug'.
- Hide C# winform App Window When Started by Task Scheduler
- how to invoke activity when app in background
- Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebug'. > Job faile
- 【Multitasking】Executing a Finite-Length Task in the Background
- 使用AS编译时,报Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build
- ANDROID打包错误ERROR:EXECUTION FAILED FOR TASK ´:APP:LINTVITALRELEASE´.
- app start after 5 seconds when pressing home button
- Error:Execution failed for task ‘:app:validateSigningRelease’. Keystore file /Users/xxx/Documents/w
- Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
- This app can’t run on your PC
- An App ID with Identifier is not available. Please enter a different string