iOS-OC-APP后台持续运行
来源:互联网 发布:怎样成为淘宝直播 编辑:程序博客网 时间:2024/04/27 15:55
//1.设置定时器@implementation AppDelegate{ NSTimer* _timer;}//2.app进入后台 启动定时器- (void)applicationWillEnterForeground:(UIApplication *)application { [_timersetFireDate:[NSDatedistantFuture]]; // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}//3.后台运行函数-(void)logAction{ NSLog(@"在后台运行");}- (void)applicationDidEnterBackground:(UIApplication *)application { _timer = [NSTimerscheduledTimerWithTimeInterval:1.0ftarget:selfselector:@selector(logAction)userInfo:nilrepeats:YES]; [[NSRunLoopcurrentRunLoop] addTimer:_timerforMode:NSDefaultRunLoopMode]; UIApplication* app = [UIApplicationsharedApplication]; __block UIBackgroundTaskIdentifier bgTask; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (bgTask != UIBackgroundTaskInvalid){ bgTask = UIBackgroundTaskInvalid; } }); }]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ dispatch_async(dispatch_get_main_queue(), ^{ if (bgTask != UIBackgroundTaskInvalid){ bgTask = UIBackgroundTaskInvalid; } }); }); // 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.}
0 0
- iOS-OC-APP后台持续运行
- IOS App 后台运行
- IOS App 后台运行
- iOS App 后台运行
- iOS后台模式以及后台持续运行
- iOS-APP后台运行代码
- iOS App 后台运行调研
- iOS让App后台运行
- iOS让App后台运行
- GCD 保持iOS app后台长时间运行
- iOS让App后台运行方法小结
- unity iOS应用切换到后台之后持续运行
- iOS 后台持续定位
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- 图形处理(十一)Stroke Parameterization
- php学习之基本语法
- popwindow 设置动画
- 五角大楼如何测试他们的飞机有多耐冻
- 图形处理(十二)拉普拉斯网格优化、最小二乘网格模型光顺
- iOS-OC-APP后台持续运行
- mysql的in选择结果过,按照in里面的排序排序
- 10019---初探JVM
- iOS程序猿之Git@OSC使用教程汇总
- 图形处理(十三)基于可变形模板的三维人脸重建-学习笔记
- python自学笔记--内嵌函数
- Drawable——VectorDrawable
- 总结使用Unity 3D优化游戏运行性能的经验
- iOS备忘录之XCode插件