about backgroundTask

beginBackgroundTaskWithExpirationHandler:

                                Marksthe beginning of anew long-running background task.

- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void(^)(void))handler

Parameters

handler

A handler to be called shortly before  the application’s remaining background time reaches 0. You should use this handler to clean up and mark the end of the background task. Failure to end the task explicitly will result in the termination of the application. The handler is called synchronously on the main thread,thus blocking the application’s suspension momentarily while the application is notified.

Return Value

A unique identifier for the new background task. You must pass this value to the endBackgroundTask:method to mark the end of this task. This method returnsU IBackgroundTaskInvalid (page 45) if running inthe background is not possible.

Discussion

This method lets your application continue to run for a period of time after it transitions to the background.You should call this method at times where leaving a task unfinished might be detrimental to your application’s user experience. For example, your application could call this method to ensure that had enough time to transfer an important file to a remote server or at least attempt to make the transfer and note any errors. You should not use this method simply to keep your application running after it moves to the background.

Each call to this method must be balanced by a matching call to theendBackgroundTask:method.Applications running background tasks have a finite amount of time in which to run them. (You can find outhow much time is available using the backgroundTimeRemaining(page 12) property.) If you do not call endBackgroundTask:for each task before time expires, the system kills the application. If you provide ablock object in thehandlerparameter, the system calls your handler before time expires to give you a chanceto end the task.

You can call this method at any point in your application’s execution. You may also call this method multipletimes to mark the beginning of several background tasks that run in parallel. However, each task must beended separately. You identify a given task using the value returned by this method.

This method can be safely called on a non-main thread.

2012-12-13 | © 2012 Apple Inc. All Rights Reserved.20

UIApplication Class Reference

Instance Methods

Availability

Available in iOS 4.0 and later.

See Also

– endBackgroundTask:(page 25)Related Sample Code

AVCam

Declared in

UIApplication.h
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值