【问题标题】:How can I track iPhone usage like the 'Moment' app does?如何像“Moment”应用一样跟踪 iPhone 的使用情况?
【发布时间】:2015-12-25 07:26:45
【问题描述】:

即使我们的应用在后台运行(未强制终止),如何跟踪 iPhone 的总使用量。最近我遇到了应用程序,即 Moment 这个应用会跟踪你的 iPhone 使用情况,即使这个应用在后台运行。实际上他们正在使用位置服务来获取执行时间。我的问题是当他们获得执行时间时,他们如何确定用户的 iPhone 屏幕是锁定还是解锁?

我有代码可以检查屏幕是锁定还是解锁

-(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];

        }

    });
}

但此代码仅在应用程序在前台运行时才有效。

【问题讨论】:

    标签: ios core-location cllocation


    【解决方案1】:

    您的代码仅在应用程序在前台运行时才有效,因为当应用程序进入后台时它不会被调用,您必须使用 background mode 之一来唤醒您的应用程序才能执行您的代码。

    【讨论】:

    • 后台模式,链接打不开
    • 您可以从项目设置的 Capabilities 选项卡中声明背景模式。启用 Background Modes 选项会将 UIBackgroundModes 键添加到应用的 Info.plist 文件中。选择一个或多个复选框会将相应的背景模式值添加到该键。
    • 好的,但我认为这不会有帮助。后台模式是获取应用程序的执行时间,使用位置更新我正在获取应用程序的执行时间,因此不需要后台模式
    • @Saurabh 是的,您可以,因为这取决于您的用例您想要跟踪的内容以及您的实施与只是分销渠道的 MDM 无关
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 2014-01-27
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多