首先,我在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上测试这个.
解决方法
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”
编辑:测试在后台启动的应用程序的另一种方法(例如:无法双击主页按钮并切换到它)是通过创建仅后台方案.转到产品 – >方案 – >管理方案,然后复制您的默认方案.
然后编辑新方案并单击选项选项卡并选中“由于后台获取事件而启动” – 当您运行应用程序时,它将直接启动到后台,就像正常使用一样.