【问题标题】:Does Apple allow to monitor springboard events?Apple 是否允许监控跳板事件?
【发布时间】:2013-05-19 12:13:29
【问题描述】:

我正在尝试检测用户何时锁定设备(例如按下主页按钮)。

Found this:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
                                    NULL, // observer
                                    lockStateChanged, // callback
                                    CFSTR("com.apple.springboard.lockstate"), // event name
                                    NULL, // object
                                    CFNotificationSuspensionBehaviorDeliverImmediately);



static void lockStateChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
    NSLog(@"event received!");
    // you might try inspecting the `userInfo` dictionary, to see
    //  if it contains any useful info
    if (userInfo != nil) {
        CFShow(userInfo);
    }
}

我可以想象 com.apple.springboard.lockstate 就像调用私有 API 一样?或者这样可以吗?

【问题讨论】:

    标签: iphone ios ipad core-foundation


    【解决方案1】:

    假设所有的 CF... 功能都是公开的,你可能没问题,但肯定是在一个模糊的区域。如果 Apple 更改该字符串,iOS 的下一个版本可能会破坏您的代码。

    在类似情况下,我对已获批准的运输应用所做的就是避免直接使用字符串。创建一个字符串数组,然后使用 NSString 方法将它们与句点分隔符组合起来,而不是直接使用 com.apple.springboard.lockstate。

    YMMV

    【讨论】:

      猜你喜欢
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 2017-08-03
      • 1970-01-01
      • 2011-09-04
      • 2021-10-19
      • 1970-01-01
      相关资源
      最近更新 更多