Can't endBackgroundTask: no background task exists with identifier, or it may have already been ended

前端 未结 9 835
时光说笑
时光说笑 2020-11-27 02:42

I am using background task to run the timer in the background to update the user\'s location. It\'s declared as:

UIBackgroundTaskIdentifier bgTask;
         


        
9条回答
  •  清歌不尽
    2020-11-27 03:11

    Are you using location update in the background?

    If yes, add the below code at the time of getting location authorization from the user - Apple changed the default for allowsBackgroundLocationUpdates to NO from iOS 9 onwards.

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
        locationManager.allowsBackgroundLocationUpdates = YES;
    }
    

    Please make sure that you activated the 'Location updates' for background modes under your project 'Signing & Capabilities'. Otherwise it will crash.

提交回复
热议问题