11

I am using a iOS 6 iphone 4S and I want to be able to send the unnoticed sms messages. So using the standard view controller won't work in this case. I tried using

- (BOOL)sendSMSWithText:(id)arg1 serviceCenter:(id)arg2 toAddress:(id)arg3;

but it doesn't send anything and returns NO. I used nil for arg2.

Can someone suggest a way to do it on iOS 6?(for jailbroken devices)

gop
  • 2,150
  • 5
  • 26
  • 54
  • 1
    Check the answer to this question: http://stackoverflow.com/questions/8932094/programatically-send-imessage-using-private-frameworks, may be of help – tttthomasssss Apr 08 '13 at 08:31
  • I was not able to use that. I had linker errors. Do you have a working sample? – gop Apr 21 '13 at 19:00

2 Answers2

15

Found out why - (BOOL)sendSMSWithText:(id)arg1 serviceCenter:(id)arg2 toAddress:(id)arg3; is not working since iOS 6.

This API is protected by the entitlement com.apple.CommCenter.Messages-send. Just sign your app with this entitlement set to true. It's much better than my another answer here (XPC method) because of the two main reasons:

  1. sendSMSWithText tells you whethere message was sent successfully
  2. Messages sent using sendSMSWithText are not being saved in the SMS database and can't be seen anywhere. On the other hand, messages sent using XPC method are being saved in SMS database and can be seen in Messages application.

So, win win. I strongly suggest dropping XPC method also because it's using pretty low level API that can change easily in new iOS version. sendSMSWithText can be found even in iOS 7 and I don't think it will be dropped any time soon.

UPDATE

In order to use this API on iOS 7 and above you need to add another entitlement with bool value set to true - com.apple.coretelephony.Identity.get.

creker
  • 9,400
  • 1
  • 30
  • 47
  • Awesome. It works perfectly, much cleaner than the XPC method (no need to use
    for line breaks) and indeed no trace of it in the database. Thank you!
    – Alexandre Blin Dec 10 '13 at 13:39
  • 1
    please tell how me how to sign this entitlement because when i try to run this app on iphone xcode gives error msg "the executable was signed with invalid entitlements" the entitlements specified in your application's code signing Entitlements file do not match those specified in your provisioning profile. – M.Shuaib Imran Feb 19 '14 at 13:47
  • Is your device jailbroken? You can't launch regular AppStore apps with these kind of entitlements. They are bundled with provisioning profile which contains the list of entitlements your app can be signed with. If app entitlements don't match with provisioning profile you will see the error. Doesn't matter if your device is jailbroken. What you need to do is sign app using `ldid` or some other tool. Then either launch it through ssh or MobileTerminal. Or copy app to `/Applications` folder and launch it from SpringBoard. – creker Feb 19 '14 at 14:14
  • I think you could build and launch your app with Xcode but you will have to jailbreak your device and install `AppSync` on it. You still can't use regular developer account. You need to use `ldid` or `codesign` to sign app with any entitlements you want. – creker Feb 19 '14 at 14:20
  • thanks for your response Now i did sign my app with ldid as "ldid -Sentitlements.plist MyApp.app/MyApp" with following in entitlements.plist com.apple.CommCenter.Messages-send com.apple.coretelephony.Identity.get – M.Shuaib Imran Feb 20 '14 at 19:00
  • Now try to do BOOL success = [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"My SMS" serviceCenter:nil toAddress:@"xxxxxxxxxxx"]; but it return false and console shows this message "Feb 21 00:02:51 iPhone : mms: Could not send message, received error: 35" AND "Feb 21 00:02:51 iPhone : mms: error sending message: 35" – M.Shuaib Imran Feb 20 '14 at 19:03
  • 1
    Sorry, don't know why it's not working for you. Those entitlements are the only things you need. – creker Feb 20 '14 at 20:54
  • Thank you so much for your guidance and help. That was happening because of my mistake i.e. my no was invalid. so that error was coming because of message sending failed. Thanks again for your help. – M.Shuaib Imran Feb 21 '14 at 07:00
  • @creker hi, i want to use sendSMSWithText in iOS8 jailbreak device , should i add these entitlements to make it work? – ximmyxiao Sep 25 '17 at 03:31
6

Straight from ChatKit.framework

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);

recipients holds serialized property list with array of phone numbers to which you want to send your SMS - 12212 is just an example of phone number. Instead of SMS text you should put actual SMS text. Unfortunately, I couldn't find a way to check whether SMS was sent successfully.

To send message using this code your application entitlements should have com.apple.messages.composeclient key with boolean value set to true. Otherwise you get error in console saying application lacks entitlement.

creker
  • 9,400
  • 1
  • 30
  • 47
  • Do you have a sample project demonstrating this? I used this exact snippet, along with OSX's xpc includes, and I can't seem to be able to send an SMS. Compiles and runs fine, but nothing is sent. – Alexandre Blin Nov 19 '13 at 18:44
  • Unfortunately, no. Did you sign your app with the entitlement? If you did I will create and post a sample project. – creker Nov 19 '13 at 21:36
  • I did. Actually I'm trying to make a simple daemon able to send SMS messages. Everything is working except actual SMS sending. I have a legit iOS dev account. – Alexandre Blin Nov 20 '13 at 07:28
  • 2
    Here is sample project https://www.sugarsync.com/pf/D201294_79891863_903386?directDownload=true How you sign your app doesn't matter - iOS dev account, self made certificate or ldid, they all work. Tested on iPhone 5 iOS 6.1 Just copied binary on device and launched it with Terminal. Very important that you have a running runloop. Otherwise SMS will not be sent and in console you will see message saying that you lack entitlement. – creker Nov 20 '13 at 20:07
  • Old thread I know but the sample project link is now dead. Anyone still have a copy of it? This won't need to pass by the app store its a private app for my friend and I. – Plasma Feb 19 '15 at 22:28
  • You really shouldn't use that solution. Accepted answer is much better and simpler – creker Feb 19 '15 at 23:24
  • I'm trying to use the accepted answer but struggling to get it working, could do with some detailed instructions. This is one of the few threads that doesn't just say "Its not possible!". the old demo project would get me out of a hole and get me on the way. – Plasma Mar 05 '15 at 23:00
  • @Plasma, old demo project contains old code that I don't even sure works any more. It was a temporal solution which doesn't work very good and looks ugly. What exactly are you struggling with in accepted answer? If you don't know how to call that method just google it and you will find examples. It's a well known API. As for entitlements, it would be offtopic to explain such a thing. Again, google it, entitlements are a well known thing. – creker Mar 06 '15 at 08:20
  • Ok so I believe I've added the entitlements, but struggling to call the API, have googled but can't find a decent example. I'm guessing I need to import some headers, currently get the message that no interface declares the selector. – Plasma Mar 06 '15 at 17:18
  • I added the CoreTelephony framework but still can't import – Plasma Mar 06 '15 at 17:25
  • @Plasma it's private header, you need download one – aelam Jun 19 '15 at 17:24
  • @aelam, no, code protected with entitlements can only be used on jailbroken devices – creker Jun 19 '15 at 17:30