应用程序未运行时的iOS 7后台提取 [英] iOS 7 Background Fetch When the App is Not Running

查看:111
本文介绍了应用程序未运行时的iOS 7后台提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的应用程序,以测试和监控文档了解详细信息:


In大多数情况下,系统在用户退出强制
后不会重新启动应用程序。一个例外是位置应用程序,在iOS 8和
之后,在用户强制退出后重新启动。


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


如果您从多任务UI中杀死一个应用程序,系统绝不会再次自动启动应用程序。这里的逻辑是,如果
用户已杀死你的应用程序,他们可能希望它保持死亡状态。


你可以做一个简单的GET请求,例如: http://dev.example.org/?ping=1 到你的网络服务器然后grep web服务器上的access.log?ping = 1



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





然后编辑新方案并单击选项选项卡并选中由于后台获取事件而启动 - 当您运行应用程序时,它将直接启动通过正常使用进入后台。




I've written a simple application in order to test and monitor how the background fetch feature works in iOS7.

First of all, I've set UIBackgroundMode options in my Info.plist file.

Then;

I added to below code into application:didFinishLaunchingWithOptions: method in AppDelegate.m:

At last, I've implemented the application:(UIApplication *)application performFetchWithCompletionHandler: method as requested.

Every time I click Debug->Simulate Background Fetch button, it changes the application's batch number and works as expected.

However, I've never been able to make it work when the application is not running (not even in the background mode, just not running).

Apple says that when the application is not running and OS wants to execute the following methods respectively:

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

So my question is that is there a way to test background fetch when the app is not running?

I am testing this on my iPod 5th Gen with iOS 7.1.

解决方案

Edit 2: Note that if a user kills the app from the app switcher, the background fetch will never happen again. This is working as Apple intended. See the related "Understanding When Your App Gets Launched into the Background" docs for details:

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.

And an old developer forums post (the link unfortunately no longer exists)...

"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."

You could make a simple GET request, eg: "http://dev.example.org/?ping=1" to your web server then grep the access.log on the web server for "?ping=1"

Edit: Another method to test the app being launched in the background (eg: without being able to double tap the home button and switch to it) is by creating a background-only scheme. Go to Product -> Scheme -> Manage Schemes and then duplicate your default scheme.

Then edit the new scheme and click the Options tab and check "Launch due to a background fetch event" - when you run your app it'll be launched directly into the background, as it would through normal use.

这篇关于应用程序未运行时的iOS 7后台提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆