CTTelephonyCenterAddObserver does not notify you of SMS messages

I have an application in which I want to respond when I receive an SMS; prior to iOS 7, this worked by registering with CTTelephonyCenter as follows:

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

and in callback verification for kCTMessageReceivedNotification. This no longer works in iOS 8, since I receive much less types of notifications than on iOS 7, and none of them are related to receiving messages. I suppose that this concerns a new law, but so far I cannot understand, if so, and what is the required law. Does anyone know how to solve this?

+5
source share
2 answers

You need to specify the name of the notification in the fourth argument:

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

Starting with iOS 8, you cannot pass NULL as the notification name to receive all CoreTelephony notifications. Now you must specify exactly which notifications you want to observe.

8.3 UPDATE

As of iOS 8.3, at least kCTMessageReceivedNotification requires the right to receive (probably the case for all notifications, but I don’t know for sure)

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

Since iOS 8.3, CTTelephonyCenterAddObserver no longer works.

+2
source

Source: https://habr.com/ru/post/1206883/


All Articles