后台提取未执行

时间:2018-01-08 11:37:02

标签: ios xamarin xamarin.ios background-fetch

iOS未执行PerformFetch

我已将应用程序置于后台并离开设备。已经过了三天,仍然没有执行PerformFetch。我知道这是因为我在MS App Center中使用事件跟踪。

public async override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{         
        Analytics.TrackEvent($"{DateTime.UtcNow} Background fetch started");

        if (App.IsSyncInProgress)
        {
            Analytics.TrackEvent($"{DateTime.UtcNow} Background fetch failed - Sync in progress");
            completionHandler(UIBackgroundFetchResult.Failed);
        }

        App.IsSyncInProgress = true;

        var loginService = App.IOCContainer.Get<ILoginService>();
        var tokenStorageService = App.IOCContainer.Get<ITokenStorage>();
        var syncService = App.IOCContainer.Get<ISyncService>();
        var userRepo = App.IOCContainer.Get<IUserRepository>();
        var sarService = App.IOCContainer.Get<ISuspiciousActivityReportService>();

        bool? result = null;

        try
        {
            if (await loginService.IsUserAuthorised())
            {
                var user = await userRepo.FetchUser();
                var bearerToken = tokenStorageService.FetchBearerToken(user.UserPrincipalName);

                if (bearerToken != null)
                {
                    result = await syncService.SyncData(bearerToken);
                    Analytics.TrackEvent($"{DateTime.UtcNow} - SyncData result: {result}");

                    result = await sarService.RetrySubmitOutstandingSuspiciousActivityReports(bearerToken);
                    Analytics.TrackEvent($"{DateTime.UtcNow} - RetrySubmitOutstandingSuspiciousActivityReports result: {result}");
                }
                else
                {
                    Analytics.TrackEvent($"{DateTime.UtcNow} - Background fetch silently failed, bearerToken is null");
                }
            }
        }
        catch (System.Net.WebException webEx)
        {
            Analytics.TrackEvent($"{DateTime.UtcNow} - Background fetch failed due to Exception: {webEx.Message}");
            completionHandler(UIBackgroundFetchResult.Failed);
        }
        catch (System.Net.Http.HttpRequestException httpEx)
        {
            Analytics.TrackEvent($"{DateTime.UtcNow} - Background fetch failed due to Exception: {httpEx.Message}");
            completionHandler(UIBackgroundFetchResult.Failed);
        }
        catch (Exception ex)
        {
            Analytics.TrackEvent($"{DateTime.UtcNow} - Background fetch failed due to Exception: {ex.Message}");
            completionHandler(UIBackgroundFetchResult.Failed);
        }
        finally
        {
            App.IsSyncInProgress = false;
        }

        var response = result == null ? UIBackgroundFetchResult.Failed : result.Value ? UIBackgroundFetchResult.NewData : UIBackgroundFetchResult.NoData;

        Analytics.TrackEvent($"Background fetch finished {DateTime.UtcNow} - result: {result}");

        //Console.WriteLine($"PeformFetch - Completed: {result}");

        // Inform system of fetch results
        completionHandler(response);
    }

我知道iOS确定何时执行后台获取但是真的吗?!三天?!

非常确定我的所有代码都是正确的,因为我可以在模拟器中成功模拟背景提取,但在真实设备上却什么也得不到。

我已经检查了设备日志并注意到iOS实际上确定不应该运行后台提取

Jan  8 10:09:28 my-iPad dasd(DuetActivitySchedulerDaemon)[105] <Notice>: com.apple.fetch.com.imptob.ituk.sara:F276C2:[
    {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
 ], FinalDecision: Must Not Proceed}

Jan  8 10:10:09 my-iPad dasd(DuetActivitySchedulerDaemon)[105] <Notice>: Submitted Activity: com.apple.fetch.com.imptob.ituk.sara:20D953 <private>

Jan  8 10:10:09 my-iPad dasd(DuetActivitySchedulerDaemon)[105] <Notice>: CANCELED: com.apple.fetch.com.imptob.ituk.sara:F276C2 <private>!

Jan  8 10:10:20 my-iPad dasd(DuetActivitySchedulerDaemon)[105] <Notice>: com.apple.fetch.com.imptob.ituk.sara:20D953:[
        {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
     ], FinalDecision: Must Not Proceed}

Jan  8 10:12:07 my-iPad assertiond[67] <Notice>: [sara.ios:666] pid_shutdown_sockets(2) success

Jan  8 10:12:09 my-iPad dasd(DuetActivitySchedulerDaemon)[105] <Notice>: com.apple.fetch.com.imptob.ituk.sara:20D953:[
    {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
 ], FinalDecision: Must Not Proceed}

我开发的以前的应用程序已经执行了后台提取而没有问题,尽管这些应用程序经常使用。

这看起来是否正常?

0 个答案:

没有答案