热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用CTMessageCenter发送SMS(ios7)-SendingSMSusingCTMessageCenter(iOS7)

IamtryingtosendsmsprogrammaticallyusingprivateAPI.Myphoneisnotjailbroken.我正在尝试使用私有AP

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

我正在尝试使用私有API以编程方式发送sms。我的手机没有越狱。

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 ?

此代码总是打印“未发送的消息”。谁能帮帮我吗?

2 个解决方案

#1


2  

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:

我猜,你必须用E.123国际表示法写电话号码。加上+号和国家代码。对于一个电话号码是USA,用+1替换领先的0:

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

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

一个电话号码是斯里兰卡使用适当的国家代码+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:

我在ios7下测试了老的ios5代码……sendSMSWithText:serviceCenter:解决:没有回报。使用新方法sendSMSWithText:serviceCenter:toAddress:withMoreToFollow:

Panagiotis' suggestion seems correct :-/

Panagiotis的建议似乎是对的:-/

UPDATE 2

更新2

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

https://stackoverflow.com/a/20425853/2270880给出了正确的答案。

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

在ios7系统下,这款应用需要两个授权许可。Messages-send com.apple.coretelephony.Identity.get。通过文件appname添加额外的权利。权限(并在target的构建设置中设置>所有的>代码签名>代码签名权限)会给您带来错误

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.

non-jailbroken设备。

#2


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

我在iOS 6.1上已经尝试了很长一段时间了,我发现这个方法在iOS 6之后就不能用了。上次我能让这个代码成功执行是在ios5上(有一个花生。应用程序在网上工作)。

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!

还没有尝试在非越狱iOS上实现。我希望你能成功!

** 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.

让我正确的自己!您的代码使用imagent可执行程序进行破解。只是无法直接从xCode应用中执行。


推荐阅读
author-avatar
可爱de小蜗牛
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有