iOS-OC-APP後臺持續執行
//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.
}
相關文章
- 通過Docker容器執行持續整合/持續部署Docker
- App切換到後臺後如何保持持續定位?APP
- oracle優化與可持續執行Oracle優化
- Web命令執行筆記(持續更新)Web筆記
- 後臺執行
- shell後臺執行
- 後臺執行MongoDBMongoDB
- 後臺執行以及保持程式在後臺長時間執行
- 育碧執行長:持續加碼中國市場
- 讓網站不停止,永遠持續執行網站
- Linux後臺執行Linux
- 後臺執行緒(daemon)執行緒
- windows redis 後臺執行WindowsRedis
- Jboss 後臺執行模式模式
- 指令碼後臺執行指令碼
- scp 在後臺執行
- 執行python指令碼後臺執行Python指令碼
- 持續整合、持續部署、持續交付、持續釋出
- linux程式前臺-後臺執行Linux
- Linux 後臺執行命令Linux
- jenkins後臺程式執行Jenkins
- linux命令後臺執行Linux
- linux後臺執行-nohupLinux
- 作業控制(後臺執行)
- Linux 下後臺執行和按照守護程式方式後臺執行的坑Linux
- 持續整合、持續交付、持續部署簡介
- java--多執行緒之後臺執行緒Java執行緒
- 持續整合持續部署持續交付_持續整合與持續部署之間的真正區別
- Laravel 持續測試主控平臺Laravel
- Jenkins搭建持續打包平臺Jenkins
- Windows 檢視系統資訊及持續執行時間 - systeminfoWindows
- 對持續整合、 持續交付、持續部署和持續釋出的介紹
- mysql後臺執行緒詳解MySql執行緒
- Mac Redis 服務後臺執行MacRedis
- Linux jar包 後臺執行LinuxJAR
- 後臺執行SQL語句(oracle)SQLOracle
- Linux 命令的後臺執行Linux
- Android Oreo 後臺執行限制Android