<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theiphonewiki.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sigmaris</id>
	<title>The iPhone Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.theiphonewiki.com/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sigmaris"/>
	<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/wiki/Special:Contributions/Sigmaris"/>
	<updated>2026-05-01T02:38:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.14</generator>
	<entry>
		<id>https://www.theiphonewiki.com/w/index.php?title=CoreTelephony&amp;diff=8442</id>
		<title>CoreTelephony</title>
		<link rel="alternate" type="text/html" href="https://www.theiphonewiki.com/w/index.php?title=CoreTelephony&amp;diff=8442"/>
		<updated>2010-08-18T21:21:12Z</updated>

		<summary type="html">&lt;p&gt;Sigmaris: Added example code to listen for incoming SMS messages&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CoreTelephony is the iPhone framework used for high-level cell modem interaction.  It handles SMS, MMS, phone calls, etc.  It is written in C, C++, and in 3.0, Objective-C portions were added.&lt;br /&gt;
&lt;br /&gt;
===Usage=== &lt;br /&gt;
In order to use CoreTelephony, you need to set up your build environment to link against it. &amp;lt;br&amp;gt;&lt;br /&gt;
You also need a set of header files, which can be obtained by using the class-dump tool on the framework.&lt;br /&gt;
&lt;br /&gt;
===C functions/types===&lt;br /&gt;
&lt;br /&gt;
  typedef struct __CTSMSMessage CTSMSMessage;&lt;br /&gt;
&lt;br /&gt;
  void*                CTTelephonyCenterGetDefault();&lt;br /&gt;
  void                 CTSMSMessageSend(void*,CTSMSMessage*);&lt;br /&gt;
  CFStringRef          CTSMSMessageCopyAddress(void *, CTSMSMessage *);&lt;br /&gt;
  CFStringRef          CTSMSMessageCopyText(void *, CTSMSMessage *);&lt;br /&gt;
  CTSMSMessage*        CTSMSMessageCreate(void*,CFStringRef number, CFStringRef name);&lt;br /&gt;
&lt;br /&gt;
====Objective-C====&lt;br /&gt;
The ObjC parts are much easier to work with because of the magic of class-dump.  The only work I've done is getting an SMS message sent out.  This can be accomplished in one line of code:&lt;br /&gt;
  [[CTMessageCenter sharedMessageCenter]  sendSMSWithText:message serviceCenter:nil toAddress:number];&lt;br /&gt;
where message and number are NSStrings filled with the correct data.&lt;br /&gt;
&lt;br /&gt;
=====Experimental code to listen for incoming SMS=====&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  static void callback(CFNotificationCenterRef center, void *observer, NSString* name, const void *object, NSDictionary* info) {&lt;br /&gt;
  fprintf(stderr, &amp;quot;Notification intercepted: %s\n&amp;quot;, [name UTF8String]);&lt;br /&gt;
  if([name isEqualToString:@&amp;quot;kCTMessageReceivedNotification&amp;quot;] &amp;amp;&amp;amp; info)&lt;br /&gt;
  {&lt;br /&gt;
    NSNumber* messageType = [info valueForKey:@&amp;quot;kCTMessageTypeKey&amp;quot;];&lt;br /&gt;
    if([messageType isEqualToNumber:[NSNumber numberWithInt:1/*empirically determined!*/]])&lt;br /&gt;
    {&lt;br /&gt;
      NSNumber* messageID = [info valueForKey:@&amp;quot;kCTMessageIdKey&amp;quot;];&lt;br /&gt;
      CTMessageCenter* mc = [CTMessageCenter sharedMessageCenter];&lt;br /&gt;
      CTMessage* msg = [mc incomingMessageWithId:[messageID intValue]];&lt;br /&gt;
      NSObject&amp;lt;CTMessageAddress&amp;gt;* phonenumber = [msg sender];&lt;br /&gt;
      &lt;br /&gt;
      NSString *senderNumber = (NSString*)[phonenumber canonicalFormat];&lt;br /&gt;
      NSString *sender = (NSString*)[phonenumber encodedString];&lt;br /&gt;
      CTMessagePart* msgPart = [[msg items] objectAtIndex:0]; //for single-part msgs&lt;br /&gt;
      NSData *smsData = [msgPart data];&lt;br /&gt;
      NSString *smsText = [[NSString alloc] initWithData:smsData encoding:NSUTF8StringEncoding];&lt;br /&gt;
      fprintf(stderr, &amp;quot;SMS Message from %s / %s: \&amp;quot;%s\&amp;quot;\n&amp;quot;,[senderNumber UTF8String],[sender UTF8String],[smsText UTF8String]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  int main(int argc, char **argv)&lt;br /&gt;
  {&lt;br /&gt;
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];&lt;br /&gt;
  &lt;br /&gt;
  id ct = CTTelephonyCenterGetDefault();&lt;br /&gt;
  CTTelephonyCenterAddObserver(ct, NULL, callback, NULL, NULL, CFNotificationSuspensionBehaviorHold);&lt;br /&gt;
  &lt;br /&gt;
  // Start the run loop. Now we'll receive notifications.&lt;br /&gt;
  [[NSRunLoop currentRunLoop] run];&lt;br /&gt;
  [pool drain];&lt;br /&gt;
  printf(&amp;quot;Unexpectedly back from CFRunLoopRun()!\n&amp;quot;);&lt;br /&gt;
  [pool release];&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sigmaris</name></author>
		
	</entry>
</feed>