6

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?

Orph
  • 145
  • 6
  • How to add this observer? Do we need to import any framework? When I add above code, I get error "Implicit declaration of function CTTelephonyCenterGetDefault is invalid in c99, conversion from int to id not allowed in arc, CTTelephonyCenterAddObserver not valid in c99 – Durgaprasad May 27 '15 at 06:59

2 Answers2

6

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>
creker
  • 9,400
  • 1
  • 30
  • 47
  • Thank you. You saved me from a lot of digging :) – Orph Nov 24 '14 at 07:13
  • Since iOS 8.3, it seems that it's no more available. I am trying with other notification that are still working on iOS 8.2 and prior. I don't know why, but it looks like Apple change the behavior of CTTelephonyCenterAddObserver. I tried to disassemble 8.2 & 8.3 CoreTelephony.framework, and all signatures seem to be the same. Do you have a workaround? Thank you. – Boobby69 Apr 10 '15 at 15:18
  • @creker what value should I use to listen to phone calls, and where is this information listed or found? Thanks! – mylord May 08 '15 at 00:29
  • @creker How do you add the entitlement? – Guntis Treulands May 05 '16 at 16:54
1

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

Deiz_84
  • 19
  • 1