简体   繁体   中英

Application didFinishLaunchingWithOption: detecting if app was launched after entering iBeacon region

An app that was not running is launched by iOS when entering an iBeacon region. The first method called is - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions . As the launching reason can differ, I'd like to be able to detect from the launching options if the launch was due to entering a specific (the one I was monitoring for) iBeacon region or not. Is this possible?

I've found the following from the ApplicationDelegate documentation but I am not convinced that is the right one as it has no direct mention of iBeacons.

UIApplicationLaunchOptionsBluetoothCentralsKey The presence of this key indicates that the app previously had one or more CBCentralManager objects and was relaunched by the Bluetooth system to continue actions associated with those objects. The value of this key is an NSArray object containing one or more NSString objects.

Each string in the array represents the restoration identifier for a central manager object. This is the same string you assigned to the CBCentralManagerOptionRestoreIdentifierKey key when you initialized the central manager object previously. The system provides the restoration identifiers only for central managers that had active or pending peripheral connections or were scanning for peripherals.

Available in iOS 7.0 and later.

To see if a beacon detection launched your app, check for the UIApplicationLaunchOptionsLocationKey . This won't tell you which CLBeaconRegion entry launched your app. For that you must wait for a subsequent didEnterRegion and check the passed value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM