CTTelephonyCenterAddObserver doesn't notify receiving SMS

2k views Asked by At

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?

2

There are 2 answers

4
creker On BEST ANSWER

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>
4
Deiz_84 On

Since iOS 8.3, the CTTelephonyCenterAddObserver don't work any more.