应用程序 didFinishLaunchingWithOption:检测应用程序是否在进入 iBeacon 区域后启动

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

不是 运行 的应用在进入 iBeacon 区域时由 iOS 启动。第一个调用的方法是 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions。由于启动原因可能不同,我希望能够从启动 选项 中检测到启动是否是由于进入特定的(我正在监视的)iBeacon 区域或不是。这可能吗?

我从 ApplicationDelegate 文档中找到了以下内容,但我不认为这是正确的,因为它没有直接提及 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.

要查看信标检测是否启动了您的应用,请检查 UIApplicationLaunchOptionsLocationKey。这不会告诉您哪个 CLBeaconRegion 条目启动了您的应用程序。为此,您必须等待后续 didEnterRegion 并检查传递的值。