Ios implements unlimited background tasks, and ios implements background tasks.
Requirement
Our app uses the heartbeat mechanism to maintain the user's login status so that we can receive messages and commands sent from the server, however, when the app enters the background for about 3 minutes or 10 minutes, the app will be suspended by the system, and the user will time out and go offline, so that the app must run in the background for a long time.
Cause
An app is generally running, in the background, or suspended on the frontend. When you press the home or screen lock key, the app will run on the background. According to Apple's official explanation, apple allows the app to run in the background for a short period of time and perform some processing. It takes about 10 minutes. After 10 minutes, the app is forcibly suspended by the system and all operations and threads are suspended, the thread is started only when the user clicks to enter this app.
Solution
1. Wireless playing of music in the app Background, Background Audio
2. Location Services
3. Background voice service and voip
4. automatically download and update newspapers and magazines in the background, Newsstand
.....
Implementation
I am using background positioning. This is the simplest method. After testing, users are online all morning, but my apps are enterprise-level applications that do not need to be launched, this solution may fail Apple's review.
Introduce header files
# Import <CoreLocation/CoreLocation. h>
Add a variable in AppDelegate. m.
@ Property (nonatomic, strong) CLLocationManager * locationManager;
Create an instance after the app is started and set the proxy
Self. locationManager = [[CLLocationManager alloc] init];
Self. locationManager. delegate = self;
After the app enters the background, it continues to locate
[Self. locationManager startUpdatingLocation];