Digital Media Mac Blogs > Mac

Programmatically Handling iPhone interruptions


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





AddThis Social Bookmark Button
Comments (22)
Read More Entries by Erica Sadun.

22 Comments

Asrekik said:

Dear Erica,
thank you for your this article.
do you know how we can send an ussd command to the gsm network such as #123#?
In you article, you displayed the way to handle the ussd message notifiactaion, but how we can send it?

Indeed, i'd like to develop an iphone application that sends an ussd command to the gsm network in order to display the account balance for prepaid user

Shikhar said:

Hello Everyone,
Is there any way to get caller number, I am able to get all notification but dont know how to get caller number.

Please help if any one know about it.

Thanks
Shikhar

Dear Erica,

I need your help,I am developing the iPhone Open ToolChain Application and having some trouble defined below.


I need your help to pick the incoming call programmatically and delete the recent call from Call history.

I have successfully got all the notification for:
1) kCTCallStatusChangeNotification(For Incoming Call)
2) kCTSIMToolkitSentUSSDNotification(For Sent USSD Message)
3) kCTCallHistoryRecordAddNotification(For adding call into call history)
4) kCTAudioVoiceMuteStatusNotification (For silence Ringing)


But now I need to pick the incoming call programmatically with no ringing and delete call record from Call history too.

I am using Open ToolChain SDK 2.0 with iphone SDK.

How to get the Callinfo for Userinof object any objcet to see that.

I have done the lot of googling but nothing found that how to get the call info data from UserInfo object in Call back method but not able to pick the incoming call programmatically.

Kindly help me to fix the above.

I will be very thankful to you.


Regards,
Amit Kushvaha

Dear Erica,

Thank you for your article about it's really helpful.

Please help me to pick the incoming call programmatically and delete the recent call from Call history.

I have successfully got all the notification for:
1) kCTAudioVoiceMuteStatusNotification(For Incoming Call)
2) kCTSIMToolkitSentUSSDNotification(For Sent USSD Message)
3) kCTCallHistoryRecordAddNotification(For adding call into call history)
4) kCTAudioVoiceMuteStatusNotification (For silence Ringing)

And i am having trouble to get the data from CFDictionaryRef Userinfo object using key.

Hoe to get the data using key.

I need to pick the incoming call programmatically with no ringing and delete call record from Call history too.

I am using Open ToolChain SDK 2.0 with iphone SDK.

Thanks in Advance.

Regards,
Amit Kushvaha

Jeepston said:

Is there any info available on core telefony notifications in 3.0? All I am getting for incoming SMS is


NOTIFICATION: kCTMessageReceivedNotification
{type = immutable, count = 2, capacity = 3, pairs = (
1 : {contents = "kCTMessageTypeKey"} = {value = +1, type = kCFNumberSInt32Type}
3 : {contents = "kCTMessageIdKey"} = {value = -2147483637, type = kCFNumberSInt32Type}
)}

How to extract sms info further (body text, address etc.)? I somehow suspect, that structure of callback function has changed...

Anna said:

I have tried to add my program as observer by CTTelephonyCenterAddObserver by I get warning that there is implicit declaration of function.

Please help to resolve warning,

Thanks,
Anna.

sandhya rai said:


Hi,

I am new to iphone , I gone through this tutorial
actually I want sample code related to the same .

Thanx in advance
sandhya

Erica Sadun said:

Just start a new file. Use the date and time as the file name. Could get really messy really quick if you get lots of phone calls.

Paul said:

Erica,
If I wanted a file to start evertime an incoming call came in or a text came in...What would i need for that? Assuming my app was already playing and I received a text or call.

Thanks!

vikky090 said:

Hello Erica,
Thank you for your for the article,
I got to know that even we can handle the call states through this site, but i have installed open sdk but not able to find the above mentioned notificaion
kCTCallStatusChangeNotification
kCTSMSMessageReceivedNotification in core telephony framework,
Please help me out to find the required header file/framework

Thanks,
vikky090

Koti said:

Hi, this Tutorial is very Good,
I am new to this Iphone application Development.

So please help me with a sample code for handling those interruptions.


Thanks in Advance,
Koti

Jaya said:

Hi Erica,

Thanks for the Reply but i want to do the same with the official SDK the latest one Beta 7, i googled it & the code i found is not working because its not giving me the access to the file required for the same.

Please help me out

Thanks Again..
Jaya

--------------------------------------------------------------------------------

Erica Sadun said:
Anatoly: Core Telephony now lives in Private Frameworks
Erez: You can intercept the SMS notification, but you can't stop them from going through.
Jaya: There is SMS sample code floating around in the jailbreak world. You should be able to google it down pretty easily
Whitney: It's not possible to disable USSD notifications from a programmatic point of view.

June 24, 2008 7:05 AM

Chak said:

How can i do it in 1.4 version?

Erica Sadun said:

Chak: It's still too early to say because the only solution will be a jailbreak one and there's no official 2.0 jailbreak yet. (Wait until 11 July).

Chak said:

I want to continuously monitor the telephone notifications and create a log of missed calls in a file.
How can i put my application as a background process?
It was nice article by the way.

Erica Sadun said:

Anatoly: Core Telephony now lives in Private Frameworks
Erez: You can intercept the SMS notification, but you can't stop them from going through.
Jaya: There is SMS sample code floating around in the jailbreak world. You should be able to google it down pretty easily
Whitney: It's not possible to disable USSD notifications from a programmatic point of view.

Anonymous said:

Core Telephony now lives in the private frameworks

Anatoly said:

Erica
Thank you for your for the article
I'm new to this amazing iPhone world and I have a question, very basic one:

Where can I find he Core Telephony framework?

Thank you in advance
Anatoly

whitney said:

Hi, I was wondering if you could tell me how to disable the ussd notification on the iphone? thanks please let me know.

Jaya said:

Hi Please let me know how to send a SMS Programmtically in iPhone...

Any sample code will be highly appreciated..


Thanks
Jaya

Erez A. Korn said:

Thank you for the article.

I understand that it should be possible to recieve incoming SMS messages this way. My questions:
1. Is it possible to delete the original message, so that my messaging application will have the only copy of the incoming SMS?
2. Is it possible to inisitate SMS sending?

Regards,
Eerz

Rikk said:

How you can find these informations ?? It's great !
Thanks Erica
Rikk

Leave a comment


Recommended for You

Topics of Interest

Archives


 
 


Or, visit our complete archive.