如何追踪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];
}
});
}
但是这段代码只在应用程序在前台运行时才能正常工作。