我正在尝试发送sms以编程方式使用私有API。我的手机没有越狱。
BOOL success = [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"test 1234..." serviceCenter:nil toAddress:@"0777888888"];
if(success){
NSLog(@"Message SENT");
}else{
NSLog(@"Message not SENT");
} 这段代码总是打印"Message not SENT“。有人能帮我吗?
发布于 2014-04-03 02:33:44
我想,你得用E.123国际记数法来写电话号码。所以添加加号和国家代码。如果电话号码是美国,请将前导0替换为+1:
[[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"test 1234..." serviceCenter:nil toAddress:@"+1777888888"];如果电话号码是斯里兰卡,请使用相应的国家/地区代码+94。
更新
我已经测试了在iOS 7下运行的旧iOS 5代码...sendSMSWithText:serviceCenter:toAddress:返回NO。在使用新方法sendSMSWithText:serviceCenter:toAddress:withMoreToFollow:时也是如此
Panagiotis的建议似乎是正确的:
更新2
https://stackoverflow.com/a/20425853/2270880给出了正确的答案。
在iOS 7下,该应用程序需要两个权限:com.apple.CommCenter.Messages-send和com.apple.coretelephony.Identity.get。通过文件appname.entitlements添加额外的授权(在目标的构建设置>全部>代码签名>代码签名授权中设置)会出现错误
The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.
(0xE8008016).在未越狱的设备上。
发布于 2013-11-02 02:50:06
我已经在iOS 6.1上尝试了很长时间,最终我发现这个方法从iOS 6开始就不能使用了。上一次我能让这段代码成功执行是在iOS 5上(在网络上有一个Peanut.app在工作)。
实际起作用的是可以找到here的内容,还可以用以下代码块讨论here。
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);不过,我还没有尝试在非越狱iOS上实现。我希望你能成功!
**编辑
让我改正自己吧!您的代码确实可以使用imagent可执行文件对越狱进行调整。只是不能直接从xCode应用程序执行它。
https://stackoverflow.com/questions/19175209
复制相似问题