Send programmatically SMS on jailbreak device

后端 未结 2 1296
南旧
南旧 2020-11-28 09:44

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

相关标签:
2条回答
  • 2020-11-28 10:07

    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.

    0 讨论(0)
  • 2020-11-28 10:13

    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.

    0 讨论(0)
提交回复
热议问题