5

I use state preservation and restoration. After simulating memory pressure using kill(getpid(), SIGKILL); , the app is killed and then is woken up, I receive notifications from the CBCentralManagerDelegate and I can communicate with peripherals.

Should restoration works after:

  1. iOS reboot?
  2. the user kills the app from the multitasking bar?

According to posts like this: Long-Term Actions after app is killed, point 2 could not be possible.

  1. If restoration does not work for 1 or 2 points, how could I "reconnet" to my peripherals in these situations?
Community
  • 1
  • 1
Maria
  • 334
  • 3
  • 17
  • After iOS reboot, I see the following in the device console. So, somehow the iPhone get battery notifications, but the app does not wake up. I have tested in iOS 7.1.1: Oct 14 12:56:13 iPhonexxxx BTLEServer[98] : (Note ) Battery level for peripheral "MyPeripheral": 92% Oct 14 12:56:18 iPhonexxxx BTLEServer[98] : (Note ) Battery level for peripheral "MyPeripheral": 92% Oct 14 12:56:23 iPhonexxxx BTLEServer[98] : (Note ) Battery level for peripheral "MyPeripheral": 92% – Maria Oct 14 '14 at 11:37

1 Answers1

7

Restoration works for cases when the app is killed by the OS:

  • call kill(getpid(), SIGKILL)
  • OS kills while in background

In any other cases, the app is not restored. The reason behind it is probably the intention that the user wanted to kill the app so it should not be re-launched. This may not be true for reboot but Apple has treated it that way so far.

No reports have shown changes so far in iOS 8 regarding the restart after reboot behavior.

There is no way to restart after a taskbar kill but for the reboot there is an alternative solution. You can register for significant location changes which will to restore the app after reboot. This has worked for me very reliably.

allprog
  • 16,540
  • 9
  • 56
  • 97
  • Thanks @allprog. Significant location changes? You mean using beacons? My peripherals are not used for location purposes, but we could considering it. – Maria Sep 30 '14 at 16:36
  • No, I mean the [CLLocationManager's significant location changes](https://developer.apple.com/Library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW8). iBeacons may also work but I haven't tried those. – allprog Oct 01 '14 at 13:32
  • i just tried the significant location changes solution but i can't manage to get it worked. My app receive the first significant location change (i launch it when i go in background) but when my phone restart my app isn't relaunched. Does the phone need a significant location change to relaunch it ? Thanks – M to the K Oct 02 '14 at 08:18
  • 1
    @MtotheK When the app is relaunched, you receive the `UIApplicationLaunchOptionsLocationKey` in the launch options in the `application:didFinishLaunchingWithOptions:` callback in the AppDelegate. If you see this, you need to make sure that you initialize the CB*Managers you use. The system will not initialize those for you automatically. The location change is only a means to wake the app reliably. – allprog Oct 02 '14 at 09:01
  • @allprog I finally manage to get it works ! However i take like 3 min after the reboot to send the notification, is it the same for you ? Thanks a lot for your help ! – M to the K Oct 02 '14 at 09:39
  • Yes, 3 minutes sounds reasonable. That's the best I could achieve too. – allprog Oct 02 '14 at 11:00
  • My app also wakes up after 3 minutes, using significant location changes. But I'm afraid Apple reject the app because I would use location manager just for this. – Maria Oct 17 '14 at 12:03