Timer: how to remain timer active in Background

前端 未结 1 511
故里飘歌
故里飘歌 2021-01-06 17:44

In my iPhone Timer Application,

In which a timer should run in background.

So, I have set the notification in appdelegate it works perfectly... With that I a

1条回答
  •  [愿得一人]
    2021-01-06 18:36

    Generally use this code for background running .In the Background timer doesn't work

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        UIApplication*    app = [UIApplication sharedApplication];
    
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:bgTask];
            bgTask = UIBackgroundTaskInvalid;
        }];
    
        // Start the long-running task and return immediately.
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
            // Do the work associated with the task.
            [self startTimerAction];
            [app endBackgroundTask:bgTask];
            bgTask = UIBackgroundTaskInvalid;
        });
    }
    

    http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW3

    0 讨论(0)
提交回复
热议问题