Can iphone app woken in background for significant location change do network activity?

后端 未结 2 1304
小蘑菇
小蘑菇 2020-12-08 03:00

I\'m working on an app that monitors significant location changes in the background. I\'ve been reading all the answers (well, I think all!) about ios4 and the application l

2条回答
  •  难免孤独
    2020-12-08 04:01

    I'd just like to confirm RedBlueThing's answer with some detail.

    I now use the following to accomplish this. bgTask is declared as UIBackgroundTaskIdentifier

    bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:
               ^{
                     [[UIApplication sharedApplication] endBackgroundTask:bgTask];
                }];
    
    // Now call methods doing network activity
    // ...
    // WHEN I KNOW THE LAST ACTION HAS COMPLETED USE THIS BLOCK OF CODE
    
    if (bgTask != UIBackgroundTaskInvalid)
    {
          [[UIApplication sharedApplication] endBackgroundTask:bgTask];
          bgTask = UIBackgroundTaskInvalid;
    }
    

    Hope this helps out since I see quite a few people looking at the question.

提交回复
热议问题