PerformFetchWithCompletionHandler called twice when simulating with Xcode

前端 未结 1 462
死守一世寂寞
死守一世寂寞 2021-02-03 17:47

In Xcode 7.0.1 the \"simulate background\" fetch command causes performFetchWithCompletionHandler to be triggered twice.

Is this an Xcode debugging error,

相关标签:
1条回答
  • 2021-02-03 18:33

    I got around this issue by declaring a static boolean in the App Delegate, and then using the boolean to get the background fetch to perform once

    if (!runOnce)
    {
        [submission startSubmissionProcessWithCompletetionHandler:^(UIBackgroundFetchResult result){
            NSDate *fetchStart = [NSDate date];
    
            completionHandler(result);
    
            NSDate *fetchEnd = [NSDate date];
            NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
            NSLog(@"Background Fetch Duration: %f seconds", timeElapsed);
        }];
        runOnce = YES;
    }
    else
    {
        completionHandler(UIBackgroundFetchResultNoData);
        runOnce = NO;
    }
    
    0 讨论(0)
提交回复
热议问题