How to properly use location in background - app got rejected 3 times

后端 未结 3 1259
轻奢々
轻奢々 2020-12-30 11:54

My app got rejected by Apple three times, all with the same rejection letter, which is:

We found that your app uses a background mode but does not inc

3条回答
  •  -上瘾入骨i
    2020-12-30 12:28

    In locationManager:didUpdateToLocation:fromLocation: or in updateMyLocationToServer: You should check if application is in background state by eg.

    [UIApplication sharedApplication].applicationState == UIApplicationStateBackground
    

    And then if Your app is in background mode You should use eg.

    backgroundTask = [[UIApplication sharedApplication]
                        beginBackgroundTaskWithExpirationHandler:
                        ^{
                            [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
                        }];
    
    /*Write Your internet request code here*/
    
    if (bgTask != UIBackgroundTaskInvalid)
    {
        [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
        bgTask = UIBackgroundTaskInvalid;
    }
    

    This way application should perform this task completely.

提交回复
热议问题