html ios background,Background Modes in iOS

*For most background modes you need to add a key in info.plist

to indicate that the app wants to run code while in the

background.

1. Click the project on the File Navigator;

2. Click info;

3. Click on the (+) that appears when you hover over any line

of the list;

4. Choose Required Background Modes in the list that appears.

When you select this item, Xcode will create an array below the

item with one blank item. Expand the list on the right and select

App plays audio. In this list, you can see all background modes

this tutorial covers - as well as a few more that you can't use

without specialized hardware.

*Receiving Location Update

You can control the accuracy of these location updates and

even change that accuracy while background.

*It is important that you call endBackgroundTask: for every

time you call beginBackgroundTaskWithExpirationHandler:.

*Processing Newsstand Kit Downloads

Newsstand mode is very specific to Newsstand apps. It provides

a set of APIs that make it easy for your app to start a very large

file download even if your app is not active (using push

notifications) and keeping going until the whole file has been

downloaded.

You can't use this mode without declaring that your app is a

Newsstand app, or the code will not work as

intended.

a4c26d1e5885305701be709a3d33442f.png

*VoIP

This mode is better than the "10min background" because you

can run the code for an indefinite amount of time. Better yet,

if the app

crashes or the user reboots the phone, the app is started

automatically in the background.

With the call to setKeepAliveTimeout:handler: you can set a

handler that will be called periodically while the app is in the

background. This allows your app to do anything, but it should be

used to send a "ping" to your server to keep the connection alive.

You've configured it to be called every 10 minutes -- the minimum

value allowed for this method, according to the documentation. All

you're doing here is sending a ping command to the server and

logging the event.

a4c26d1e5885305701be709a3d33442f.png

Your handler has a maximum of 10 seconds to perform any needed

tasks and exit. If it does not exit before time expires, the app is

suspended.

Timeout values and handlers are not persisted between app

launches. Therefore, if your app is terminated for any reason, you

must reinstall the handler during the next launch cycle.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值