Programmatically Handling iPhone interruptions

 

http://blogs.oreilly.com/digitalmedia/2008/02/when-it-comes-to-the.html

 

When it comes to the iPhone, phone function comes first. Incoming calls, SMS, and USSD (unstructured supplementary service data, including account balance notifications for prepaid plans) messages will supersede your application. You can program around this by watching for core telephony events and shutting down key processes as needed. The iPhone's core telephony system sends out distributed notifications to warn about these status changes.

To add core telephony notification to your program, include the following code and compile linking to the Core Telephony framework. This code adds your program as a registered observer.

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

To monitor the incoming notifications, you need to build the callback routine you supplied as an argument to the add observer call:

static void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { ... }

The notification is sent as the name in this callback and supporting data is sent as a dictionary of information (userInfo). Use the toll-free bridging between CFStringRef and NSString to apply a simple isEqualToString: method and check which notification was sent.

The keys you will want to watch for are as follows:

kCTCallStatusChangeNotification A call was received or ended.

kCTSMSMessageReceivedNotification An SMS message was received.

kCTUSSDSessionBeginNotification, kCTUSSDSessionStringNotification, and kCTUSSDSessionEndNotification USSD message sessions may use all three of these notifications.

Categories

你可能感兴趣的:(null,iPhone,callback,sms,Dictionary,notifications)