【发布时间】:2015-12-25 07:26:45
【问题描述】:
即使我们的应用在后台运行(未强制终止),如何跟踪 iPhone 的总使用量。最近我遇到了应用程序,即 Moment 这个应用会跟踪你的 iPhone 使用情况,即使这个应用在后台运行。实际上他们正在使用位置服务来获取执行时间。我的问题是当他们获得执行时间时,他们如何确定用户的 iPhone 屏幕是锁定还是解锁?
我有代码可以检查屏幕是锁定还是解锁
-(void)registerAppforDetectLockState {
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate", ¬ify_token,dispatch_get_main_queue(), ^(int token) {
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
if(state == 0) {
NSLog(@"unlock device");
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"unlock device" message:@"test" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
} else {
NSLog(@"lock device");
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"lock device" message:@"test" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
});
}
但此代码仅在应用程序在前台运行时才有效。
【问题讨论】:
标签: ios core-location cllocation