美文网首页
App Programming Guide for iOS

App Programming Guide for iOS

作者: 杰米 | 来源:发表于2016-11-04 15:09 被阅读170次

The App Life Cycle

Execution States for Apps

后台状态重要区分
Background:
app在后台,而且仍然执行代码,Background的程序呗系统终止后会收到applicationWillTerminate:一系列通知
Suspend:
app在后台但是不执行代码,Suspend的程序被系统或人为终止后不会收到任何通知,进入后台在特定时间内没有后台操作系统将会讲app挂起

The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.


Executing Finite-Length Tasks

Apps moving to the background are expected to put themselves into a quiescent state as quickly as possible so that they can be suspended by the system. If your app is in the middle of a task and needs a little extra time to complete that task, it can call the beginBackgroundTaskWithName:expirationHandler: or beginBackgroundTaskWithExpirationHandler:method of the UIApplication object to request some additional execution time. Calling either of these methods delays the suspension of your app temporarily, giving it a little extra time to finish its work. Upon completion of that work, your app must call the endBackgroundTask: method to let the system know that it is finished and can be suspended.


Downloading Content in the Background

The process for creating a configuration object that supports background downloads is as follows:

  1. Create the configuration object using the backgroundSessionConfigurationWithIdentifier: method of NSURLSessionConfiguration.
  2. Set the value of the configuration object’s sessionSendsLaunchEvents property to a YES/a.
  3. if your app starts transfers while it is in the foreground, it is recommend that you also set the discretionary property of the configuration object to a YES/a.
  4. Configure any other properties of the configuration object as appropriate.
  5. Use the configuration object to create your NSURLSession object.

Implementing Long-Running Tasks

Using Push Notifications to Initiate a Download

收到一个远程通知可以启用application:didReceiveRemoteNotification:fetchCompletionHandler:来提前从服务器拉数据

Being a Responsible Background App

Save your app state before moving to the background.
During low-memory conditions, background apps may be purged from memory to free up space. Suspended apps are purged first, and no notice is given to the app before it is purged. As a result, apps should take advantage of the state preservation mechanism in iOS 6 and later to save their interface state to disk. For information about how to support this feature, see Preserving Your App’s Visual Appearance Across Launches.

Strategies for Handling App State Transitions

todo

相关文章

网友评论

      本文标题:App Programming Guide for iOS

      本文链接:https://www.haomeiwen.com/subject/vlxwuttx.html