Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 903
Orph Avatar asked Nov 14 '14 15:11

Orph


2 Answers

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>
like image 186
creker Avatar answered Oct 19 '22 00:10

creker


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

like image 43
Deiz_84 Avatar answered Oct 18 '22 23:10

Deiz_84