Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically force an iOS 7 app to suspend?

Tags:

ios

I am trying to force my app to automatically enter the "Suspended" state programmatically, so I can do testing on Core Bluetooth restoration. I have tried calling

[[UIApplication sharedApplication] performSelector:@selector(suspend)];

but this merely sends it into the background. Am I doing it wrong? Is there a better way? Or is it impossible?

I would like to remind everyone exactly what it means to have an app be suspended, as there is always confusion on the terminology: Link to state diagram of iPhone apps
(source: apple.com)

An app in the background will get indefinitely suspended if the system needs memory, but Core Bluetooth's restoration can send an app back into the background state temporarily.

like image 803
Jegus Avatar asked Nov 15 '13 21:11

Jegus


1 Answers

I don't know how to do this programmatically, but what I do is to press the home button, then launch a number of heavyweight apps like Safari and graphics-intensive games. The memory pressure causes the system to terminate your app pretty quickly. Core Bluetooth should then initiate the restore process and re-launch your app when it detects activity from a peripheral you are connected to/have asked to connect to.

like image 191
Duncan C Avatar answered Sep 18 '22 09:09

Duncan C