I'm trying to do some network requests in a BGAppRefreshTask's lanchHandler, but I'm getting some crashes. It is hard to recreate the crash on my now device. The crash count / DAU is about 1% according to log, by the way, my app is running under an enterprise account.
The last lines of the crash log is like:
0 CoreFoundation 0x0000000196475e48 __exceptionPreprocess + 164
1 libobjc.A.dylib 0x000000018f7478d8 objc_exception_throw + 60
2 Foundation 0x0000000190d3694c _userInfoForFileAndLine + 0
3 BackgroundTasks 0x00000001feb7fcfc -[BGTaskScheduler _callRegisteredHandlersForActivities:] + 528
4 BackgroundTasks 0x00000001feb7d184 -[BGTaskScheduler _handleAppLaunch] + 324
5 BackgroundTasks 0x00000001feb7cfdc __50+[BGTaskScheduler _applicationDidFinishLaunching:]_block_invoke + 52
...
It also shows: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No launch handler registered for task with identifier com.my.identifier’
I believe I have done all the necessary steps(I setup according to the demo: https://developer.apple.com/documentation/backgroundtasks/refreshing_and_maintaining_your_app_using_background_tasks) to setup BGTask, I call BGTaskScheduler’s register method in the app's didFinishLaunchingWithOptions, and call BGTaskScheduler’s submit method in the app's applicationDidEnterBackground method, I also call BGTaskScheduler’s submit method in the BGTask's launchHandler(because I want to trigger the task more than one time after into background).
Since the error info is No launch handler registered, but I actually call register in the didFinishLaunchingWithOptions, is it possible that the register method failed for other some reason except for not adding the identifier in the info.plist?
Does anyone know why the launchHandler is not registered? What do I miss?
Thank you all in advance