Search code examples
iosios8jailbreakcore-telephony

CTTelephonyCenterAddObserver doesn't notify receiving SMS


I have an app where I want to react when a SMS is received; up until iOS 7 this worked by registering to CTTelephonyCenter like this:

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

and in the callback checking for kCTMessageReceivedNotification. This does not work in iOS 8 anymore, as I receive far less notification types than on iOS 7, and none related to message receiving. I assume this is about a new entitlement, but could not figure yet if so, and what is the entitlement needed. Does anybody know how to solve this?


Solution

  • You need to specify notification name in fourth argument:

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

    As of iOS 8 you can't pass NULL as notification name to recieve all CoreTelephony notifications. Now you must tell it exactly which notifications you want to observe.

    8.3 UPDATE

    As of iOS 8.3 at least kCTMessageReceivedNotification requires entitlement to be received (probably the case for all notifications but don't know for sure)

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