4

I am trying to send sms programmatically using private API. My phone is not jailbroken.

BOOL success =  [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"test 1234..." serviceCenter:nil toAddress:@"0777888888"];
if(success){
    NSLog(@"Message SENT");
}else{
    NSLog(@"Message not SENT");
} 

This code always prints "Message not SENT". Can anyone help me ?

Charles
  • 50,943
  • 13
  • 104
  • 142
Thilina Chamath Hewagama
  • 9,039
  • 3
  • 32
  • 45

2 Answers2

3

I guess, you have to write the telephone number in E.123 international notation. So add plus sign and country code. For a phone number is USA replace the leading 0 with +1:

[[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"test 1234..." serviceCenter:nil toAddress:@"+1777888888"];

For a phone number is Sri Lanka use the appropriate country code +94.

UPDATE

I've tested old working iOS 5 code under iOS 7... sendSMSWithText:serviceCenter:toAddress: returns NO. The same while using the new method sendSMSWithText:serviceCenter:toAddress:withMoreToFollow:

Panagiotis' suggestion seems correct :-/

UPDATE 2

https://stackoverflow.com/a/20425853/2270880 gives the right answer.

Under iOS 7 the app needs two entitlements com.apple.CommCenter.Messages-send and com.apple.coretelephony.Identity.get. Adding additional entitlements via file appname.entitlements (and set in target's Build Settings > All > Code Signing > Code Signing Entitlements) give you the error

The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.
(0xE8008016).

on non-jailbroken devices.

Community
  • 1
  • 1
AppsolutEinfach
  • 1,421
  • 1
  • 14
  • 25
1

I have been trying to do this on iOS 6.1 for way long and as I figured out eventually this method could not be used since iOS 6. Last time I could make this code execute successfully was on iOS 5 (there is a Peanut.app on the web working).

What actually worked is what can be found here and discussed here as well with the following code block.

dispatch_queue_t queue = dispatch_queue_create("com.apple.chatkit.clientcomposeserver.xpc_connection_queue", DISPATCH_QUEUE_SERIAL);
xpc_connection_t connection = xpc_connection_create_mach_service("com.apple.chatkit.clientcomposeserver.xpc", queue, 0);
xpc_connection_set_event_handler(connection, ^(xpc_object_t){});
xpc_connection_resume(connection);
dispatch_release(queue);

xpc_object_t dictionary = xpc_dictionary_create(0, 0, 0);
xpc_dictionary_set_int64(dictionary, "message-type", 0);
NSData* recipients = [NSPropertyListSerialization dataWithPropertyList:[NSArray arrayWithObject:@"12212"] format:NSPropertyListBinaryFormat_v1_0 options:0 error:NULL];
xpc_dictionary_set_data(dictionary, "recipients", recipients.bytes, recipients.length);
xpc_dictionary_set_string(dictionary, "markup", "SMS text");

xpc_connection_send_message(connection, dictionary);
xpc_release(dictionary);

Haven't tried to implement on non-jailbreak iOS though. I hope you can make it!

** EDIT

Let me correct myself! Your code does work on a jailbreak tweak using the imagent executable. Just couldn't execute it straight from an xCode app.

Community
  • 1
  • 1
Panagiotis
  • 309
  • 2
  • 13