如何解决iOS后台应用程序提取不起作用?

如何解决iOS后台应用程序提取不起作用?,第1张

概述我正在尝试让iOS后台应用程式提取在我的应用程式中工作。在Xcode测试时,它可以在设备上运行时不起作用! >我的测试设备正在运行iOS 9.3.5(我的部署目标是7.1) >我在Xcode中的目标“功能”下的“后台模式”下启用了“后台提取”功能 在应用程序:didFinishLaunchingWithOptions我已经尝试过各种间隔与setMinimumBackgroundFetchInter 我正在尝试让iOS后台应用程式提取在我的应用程式中工作。在Xcode测试时,它可以在设备上运行时不起作用!

>我的测试设备正在运行iOS 9.3.5(我的部署目标是7.1)
>我在Xcode中的目标“功能”下的“后台模式”下启用了“后台提取”功能

在应用程序:dIDFinishLaunchingWithOptions我已经尝试过各种间隔与setMinimumBackgroundFetchInterval,包括UIApplicationBackgroundFetchIntervalMinimum

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    // tell the system we want background fetch    //[application setMinimumBackgroundFetchInterval:3600]; // 60 minutes    [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];    //[application setMinimumBackgroundFetchInterval:1800]; // 30 minutes    return YES;}

我已经实现了应用程序:performFetchWithCompletionHandler

voID (^fetchCompletionHandler)(UIBackgroundFetchResult);NSDate *fetchStart;-(voID)application:(UIApplication *)application performFetchWithCompletionHandler:(voID (^)(UIBackgroundFetchResult))completionHandler{    fetchCompletionHandler = completionHandler;    fetchStart = [NSDate date];    [[NSUserDefaults standardUserDefaults] setobject:fetchStart forKey:kLastCheckedContentDate];    [[NSUserDefaults standardUserDefaults] synchronize];    [FeedParser parseFeedAtUrl:url withDelegate:self];} -(voID)onParserFinished{    DDLogVerbose(@"AppDelegate/onParserFinished");    UIBackgroundFetchResult result = UIBackgroundFetchResultNoData;    NSDate *fetchEnd = [NSDate date];    NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];    DDLogVerbose(@"Background Fetch Duration: %f seconds",timeElapsed);    if ([self.mostRecentContentDate compare:item.date] < 0) {        DDLogVerbose(@"got new content: %@",item.date);        self.mostRecentContentDate = item.date;        [self scheduleNotificationWithItem:item];        result = UIBackgroundFetchResultNewData;    }    else {        DDLogVerbose(@"no new content.");        UIlocalnotification* localnotification = [[UIlocalnotification alloc] init];        localnotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];        localnotification.alertbody = [Nsstring stringWithFormat:@"Checked for new posts in %f seconds",timeElapsed];        localnotification.timeZone = [NSTimeZone defaultTimeZone];        [[UIApplication sharedApplication] schedulelocalnotification:localnotification];    }    fetchCompletionHandler(result);}

>我有(成功!)测试与模拟器和设备使用Xcode的DeBUG / SimulateBackgroundFetch
>我已经通过另一个SO答案(http://stackoverflow.com/a/29923802/519030)所示的新计划成功测试了
>我的测试显示执行在performFetch方法的代码大约0.3秒(所以它不需要很长时间)
>我已经验证设备在设置中启用了后台刷新功能。
>当然,我已经看过其他的SO问题,希望有人经历过同样的事情。 总结

以上是内存溢出为你收集整理的如何解决iOS后台应用程序提取不起作用?全部内容,希望文章能够帮你解决如何解决iOS后台应用程序提取不起作用?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1073653.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存