Jegus
Jegus

Reputation: 165

Programmatically force an iOS 7 app to suspend?

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.

Upvotes: 10

Views: 3243

Answers (1)

Duncan C
Duncan C

Reputation: 131408

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.

Upvotes: 6

Related Questions