How to save the application for more than 10 minutes. in the background?

I know that in iOS, background apps can only work

  • Tasks of the final length (10 minutes)
  • Location updates
  • VoIP
  • Audio

Is there a way that my application cannot be terminated after 10 minutes. in the background? I will not send my application to the application store, so everything is allowed (private frameworks using gps, even if I do not need it). I know that the apple does not recommend this, but it is just for monitoring purposes. I need it to work without restrictions.

I explored several possibilities, including VoIP, but it gives me 30 seconds every 10 minutes, which is not enough. I also read this post: iPhone - Poll information for events in which JackPearse pointed out a way to spice up a 10-minute finite-length task using a VoIP 30 second task. But I do not want my task to begin and end every 10 minutes, it should work continuously. I also tried it UPDATE2, but it does not work for me. I even tried to intercept UIEvent with GSEvent.type 2012, which seemed to be completing my background job, but no luck. Oddly enough, my background task never ends when I open and debug Xcode, but when I do not (test only the simulator), it ends in 10 minutes.

+4
source share
2 answers

I learned how to keep my application in the background for more than 10 minutes, continuously playing a song in the background. On AppDidFinishLauching:

[[AVAudioSession sharedInstance] setActive:YES error:&error]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]; NSURL *url = [NSURL fileURLWithPath:...]; //Song URL AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; player.numberOfLoops = -1; [player play]; 

In AppDidEnterBackground, you can execute a selector in the background, which can last forever. The application will not be interrupted, you can check the UIApplication backgroundtimeRemaining value and see that it never decreases.

Of course, declare the application a background audio application in plist.

+1
source

I already tried somehow ( nsrunloop , * performselectoronmainthread *) similar to this. It works well in the simulator (not in the device, because the apple automatically works sometimes) when the application goes into the background.

status is a BOOL variable.

 - (void)applicationDidEnterBackground:(UIApplication *)application { while (!**status**) { [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:60.0]]; [self goBackground]; } } 
+1
source

Source: https://habr.com/ru/post/1401125/