ios - CTTelephonyCenterAddObserver 不通知接收短信

标签 ios ios8 jailbreak core-telephony

我有一个应用程序,我想在收到短信时使用react;在 iOS 7 之前,这可以通过像这样注册到 CTTelephonyCenter 来实现:

        id center = CTTelephonyCenterGetDefault();
        CTTelephonyCenterAddObserver(center,
                                     NULL,
                                     callback,
                                     NULL,
                                     NULL,
                                     CFNotificationSuspensionBehaviorHold);

并在回调中检查 kCTMessageReceivedNotification。这在 iOS 8 中不再起作用,因为我收到的通知类型比 iOS 7 少得多,而且与消息接收无关。 我认为这是关于一项新的权利,但还不能确定是否是这样,以及需要什么权利。有人知道如何解决这个问题吗?

最佳答案

您需要在第四个参数中指定通知名称:

id center = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(center,
                             NULL,
                             callback,
                             CFSTR("kCTMessageReceivedNotification"),
                             NULL,
                             CFNotificationSuspensionBehaviorHold);

从 iOS 8 开始,您无法通过 NULL 作为通知名称来接收所有 CoreTelephony 通知。现在您必须准确地告诉它您想要观察哪些通知。

8.3 更新

从 iOS 8.3 开始,至少 kCTMessageReceivedNotification 需要接收授权(可能是所有通知的情况,但不确定)

<key>com.apple.CommCenter.fine-grained</key>
<array>
    <string>spi</string>
</array>

关于ios - CTTelephonyCenterAddObserver 不通知接收短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26932913/

相关文章:

xcode - 模拟器上的越狱应用程序?

ios - 如何获得iOS应用程序的root特权?

UITabBarController 和 UINavigation Controller 的 iOS8 旋转问题

ios - 特立独行者和 iOS 7 的 Theos 错误

ios - 无法在一个 Storyboard 中显示两个选择器 View

android - 我可以将 Xamarin.Android 移植到 Xamarin.ios 应用程序吗?

ios - 自定义上拉刷新 Swift

ios - 如何在 Swift 中创建嵌入式 JSON 对象并返回字符串?

ios - iPhone 6/iOS 8.3 屏幕尺寸错误?

ios - SpriteKit : How can I determine when methods like applyImpulse on a physicsbody are done?