Programmatically Handling iPhone interruptions

來源:互聯網
上載者:User

 

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


Mac

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.