应用程序未运行时的iOS 7后台提取

我编写了一个简单的应用程序,以测试和监控 background fetch功能在iOS7中的工作方式.

首先,我在Info.plist文件中设置了UIBackgroundMode选项.

然后;

我将以下代码添加到appDelegate.m中的application:didFinishLaunchingWithOptions:方法中:

最后,我实现了应用程序:(UIApplication *)应用程序
performFetchWithCompletionHandler:请求的方法.

每次我单击Debug-> Simulate Background Fetch按钮时,它都会更改应用程序的批号并按预期工作.

但是,当应用程序未运行时,我甚至无法使其工作(即使在后台模式下也没有运行).

Apple表示,当应用程序未运行且操作系统分别要执行以下方法时:

application:(UIApplication *)application didFinishLaunchingWithOptions:
applicationDidEnterBackground:(UIApplication *)application
application:(UIApplication *)application performFetchWithCompletionHandler:

所以我的问题是,有没有办法在应用程序未运行时测试后台提取?

我正在使用iOS 7.1在iPod 5th Gen上测试这个.

解决方法

编辑2:请注意,如果用户从应用切换器中杀死应用,则后台提取将永远不会再次发生.这正如Apple所期望的那样.有关详细信息,请参阅相关的 “Understanding When Your App Gets Launched into the Background”文档:

In most cases,the system does not relaunch apps after they are force
quit by the user. One exception is location apps,which in iOS 8 and
later are relaunched after being force quit by the user.

一个旧的开发者论坛帖子(遗憾的是链接不再存在)……

“If you kill an app from the multitasking UI,the system will never
automatically launch the app again. The logic here is that,if the
user has killed your app,they probably want it to stay dead.”

您可以向Web服务器发出一个简单的GET请求,例如:“http://dev.example.org/?ping=1”,然后grep web服务器上的access.log“?ping = 1”

编辑:测试在后台启动的应用程序的另一种方法(例如:无法双击主页按钮并切换到它)是通过创建仅后台方案.转到产品 – >方案 – >管理方案,然后复制您的默认方案.

然后编辑新方案并单击选项选项卡并选中“由于后台获取事件而启动” – 当您运行应用程序时,它将直接启动到后台,就像正常使用一样.

以上是来客网为你收集整理的应用程序未运行时的iOS 7后台提取全部内容,希望文章能够帮你解决应用程序未运行时的iOS 7后台提取所遇到的程序开发问题。

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