Science:

In fact, the APP has four background modes, no matter which background mechanism, it needs to use the corresponding background interface provided by Apple to achieve. In IOS7, developers can flexibly use a variety of background interfaces (apis) to achieve more intelligent application operations. ##### 1, no background only push The first background mode is the traditional no background operation, only Apple push mechanism, this mode appears in most system versions of iOS 3.x and below. In this way, the app will close and exit after pressing the Home button, and its data will be transmitted through the push server built by Apple, without the need for the app to run in the background. The reason why this approach is not good is that after each launch, re-entry needs to be re-loaded. Although push can uniformly solve the transmission of data and information, it will appear bad experience when you need to frequently enter the application (such as chat APP). ##### 2, tombstone The second approach is the tombstone background mechanism, which has been widely adopted since iOS 4, which is known as pseudo-multitasking. This is an improvement over the first one. When you press the Home button to go to the Home screen, the app goes into the background, but it freezes and doesn’t do anything. ##### 3. Intelligent scheduling background The third type is the background of system intelligent scheduling. Background Fetch is newly added in iOS 7, and this background interface is mentioned in Apple WWDC 2013. For example, if the background information of some social networking and news applications is new, the iOS system will intelligently allocate the background acquisition frequency and startup duration of each application according to the application startup frequency and time, and the current network and battery status. Background data refresh operations of applications with this interface are scheduled uniformly. Therefore, the system can obtain data of multiple applications in one process, which is similar to a unified push mechanism, thus saving power as much as possible. The downside of this approach is that developers can’t specify when the data will be updated, so this background approach can only be used in areas with limited timeliness and sensitivity. ##### 4, true background The fourth way is the true background mechanism, but the iOS true background mechanism is different from the Android background mechanism, in order to give consideration to the system experience and unified process management, iOS has added many restrictions on this. Background Audio is the Background Audio, which has been around for a long time and is also the most widely used Background application on iOS devices. Music playing in the Background can be realized by calling this interface. 2, Location Services, this is the background positioning, the system will have a unified page for management. 3, VoIP, background voice service, similar to Skype call applications need to be called, can be background voice call. 4, Newsstand, newspapers and magazines background automatic download update, which can be automatically updated in real time. 5. Background Task Completion: This interface has been available since iOS 4, and can be used by any type of APP. However, in the old system, the Background limit of this interface is only 10 minutes, which means that when the application is retired to the Background, It runs in the background for only 10 minutes before going to sleep. IOS 7 gave a change to the interface, the original is for 10 minutes, namely whether or not you 10 minutes the user to shut down the screen to enter a dormant state, the application will still be waiting for 10 minutes in the background is introduced, and the new improved as if encounter closed screen dormancy, the background of 10 minutes will follow sleep together, The remaining background time will be calculated after the user wakes up the device again. The background running time is still 10 minutes, but it is not continuous, which has the advantage of saving power. For example, there are some dictionary applications with the function of background copy word selection, which actually makes use of this interface. If the user opens the dictionary and launches it, even if the screen is closed, the dictionary is still running in the background, and the power consumption is relatively large. On iOS 7, this problem can be solved. 6. Remote Notification is a major improved interface this time. In the past, chat apps need to receive information again after receiving push, which is most obvious in QQ, wechat and other apps. With this interface, however, this will no longer be the case and push will be able to launch background tasks directly. It’s worth noting that Remote Notification supports Silent Notification, which allows synchronization apps like Dropbox to synchronize in real time in the background in the most energy-efficient mode. Similar to the burqa cartoon, it can also push the new chapter of the manpainting that is being followed and download it silently in the Background. After downloading it, it will send a local push to the user. The user can click on it and see that there is no need to connect to the Internet. IOS is the most similar to the traditional multitasking background interface, which can be called by any type of app without time limit. Application scenarios include uploading and downloading data in the background, which makes it possible to update data packets in the background, upload videos in the background and so on, but as its name suggests, it can only be used for uploading and downloading transfer tasks, not for background clipboard monitoring.

Configure background running permission:

Code:

Request background location permission:

 if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
        [self.locationManager requestAlwaysAuthorization];
    }
Copy the code

Background run, resistance to program kill

[self.locationManager setAllowsBackgroundLocationUpdates:YES];
self.locationManager.pausesLocationUpdatesAutomatically = NO;
Copy the code
## Pro test perfect, failed to achieve the students please leave a message.Copy the code