Post

Replies

Boosts

Views

Activity

How can I tell my app is launched via BGAppRefreshTask/BGProcessTask?
I need to know if my app is launched via BGAppRefreshTask/BGProcessTask in UIApplicationDelegate's application:didFinishLaunchingWithOptions: method, but the launchOptions didn't contain any key about this. A workaround is to check if UIApplication sharedApplication].applicationState == UIApplicationStateBackground in application:didFinishLaunchingWithOptions:, but it cannot tell launch via BGTask part from launch via other methods like silent push.
0
0
284
Jul ’23
Will application:didFinishLaunchingWithOptions be executed during a BGAppRefreshTask?
I'm almost certain the answer is YES because of this doc: https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence. however, the screenshot in the article shows that the Background Modes only contains Background fetch, not Background processing, this is the situation before iOS 13, so I guess this screenshot (or this article) is a little out of date. So can anyone help me to confirm that whether application:didFinishLaunchingWithOptions will be executed during a BGAppRefreshTask after the app is terminated?
0
0
363
Mar ’23
I got a crash while using BGTask / BGAppRefreshTask
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
1
2
1.1k
Feb ’23
Is it possible to achieve partial preloading of videos(mp4 and hls) via AVAssetDownloadTask
My app uses AVPlayer for video playback, and now I have a requirement to start pre-loading video content before entering the video playback page. I want to pre-load as little content as possible, as long as the video can start playing quickly after entering the video playback page. It seems that AVAssetDownloadTask can achieve my requirement, but I encountered several problems How can I control the AVAssetDownloadTask to load only the first few seconds of the video before going to the video playback page? How to bind the first few seconds of the downloaded part of the video to the url , so that I can continue to use the downloaded part to quickly open the video after I restart the app. Does AVAssetDownloadTask support mp4 to achieve the same function?
1
0
586
Dec ’22
Will BGAppRefreshTask be triggered when app is killed for OOM in the background?
I know that BGAppRefreshTask will not be triggered in background when user has forced killed the app. But if user only presses the home button or swipes up the screen to make the app info background, and after a while the app was terminated in the background for OOM, will BGAppRefreshTask still be triggered in this case?
2
0
1.2k
Dec ’22
Is gethostbyname safe?
I'm trying to convert the url to IP address during app startup by using the method gethostbyname, and in this way, let the system cache the IP address, so that in later webview and NSURLSession network requests, can skip the DNS stage and send requests directly to the IP address. My question is, first of all, is gethostbyname safe? I see that gethostbyname is a synchronous method and may cause crash, so I put it in a background current queue and use try-catch to protect it, will this prevent crashes from happening? Secondly, is gethostbyname the best solution to this problem? I know CFHost also has API to convert url to ip, but CFHostStartInfoResolution and CFHostGetAddressing are already marked as deprecate, is there any other solution?
7
0
936
Dec ’22