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

前端 未结 9 846
时光说笑
时光说笑 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:18

    I had the same issue and figured out the cause and solution!

    Apple has fixed this issue in iOS 13.4 GM though I have workaround for the earlier versions.

    While you should embrace using scenes when your app is run under iOS 13 and later, you can fully opt-out while you still support iOS 12 or earlier.

    1. First, completely remove the “Application Scene Manifest” entry from Info.plist.
    2. If there is a scene delegate class, remove it.
    3. If there are any scene related methods in your app delegate, remove those methods.
    4. If missing, add the property var window: UIWindow? to your app delegate.
    5. Your app should now only use the app delegate and under iOS 13 it should have the same life cycle as iOS 12.

    Happy coding!

提交回复
热议问题