简体   繁体   English

如何跟踪“Moment”应用程序的iPhone使用情况?

[英]How can I track iPhone usage like the 'Moment' app does?

How to track total usage of iPhone, even if our app is running in background(not forcefully terminated). 如何跟踪iPhone的总使用量,即使我们的应用程序在后台运行(没有强制终止)。 Recently i have come across app, namely Moment this app does track your iPhone usages, even if this app is running in background. 最近我遇到了应用程序,即Moment这个应用程序确实跟踪你的iPhone用法,即使这个应用程序在后台运行。 actually they are using location service to get execution time. 实际上他们正在使用位置服务来获取执行时间。 my question is when they get execution time, how they can be sure if user's iPhone screen lock or unlock ? 我的问题是,当他们获得执行时间时,他们如何确定用户的iPhone屏幕锁定或解锁?

i have code to check if screen is lock or unlock 我有代码检查屏幕是锁定还是解锁

-(void)registerAppforDetectLockState {

    int notify_token;
    notify_register_dispatch("com.apple.springboard.lockstate", &notify_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];

        }

    });
}

but this code is working only when app is running in foreground. 但此代码仅在app在前台运行时才有效。

您的代码仅在应用程序在前台运行时才起作用,因为当应用程序进入后台时,它不会被调用,您必须使用其中一种后台模式来唤醒您的应用程序才能执行您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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