我正在创建一个显示监视器iBeacon区域的应用程序,这意味着当设备被锁定并且在信标范围内时,我的应用程序的图标会显示在左下角的锁定屏幕上。
有什么方法可以检测我的应用是通过此锁定屏幕图标启动,并运行一些代码?
答案 0 :(得分:1)
当图标出现时,表示已输入信标区域。首次出现图标时,系统会调用CLLocationManager
代理的didEnterRegion
方法。
您可以在其中放置自定义代码以设置指示图标出现的标记。
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
_iconShown = YES;
}
然后,当您的应用程序到达前台时,您可以检查此标志以查看它是否已设置,并执行您的自定义逻辑:
- (void)applicationWillEnterForeground:(UIApplication *)application {
if (_iconShown) {
_iconShown = NO;
// Put custom logic here for launching from the icon
}
}
答案 1 :(得分:0)
self.backgroundedToLockScreen
,如:
- (void)applicationWillEnterForeground:(UIApplication *)application {
if (self.backgroundedToLockScreen) {
... // app was backgrounded to lock screen
} else {
... // app was backgrounded on purpose by tapping the home button or switching apps.
}
self.backgroundedToLockScreen = NO;
}
和
- (void)applicationWillEnterForeground:(UIApplication *)application {
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (UIApplicationStateInactive == state || // detect if coming from locked screen (iOS 6)
self.backgroundedToLockScreen) // detect if backgrounded to the locked screen (iOS 7)
{
... // app is coming from or was backgrounded to lock screen
} else {
... // app was backgrounded on purpose by tapping the home button or switching apps
}
self.backgroundedToLockScreen = NO;
}
希望这对你有用。