使用CTMessageCenter发送短信(iOS 7) [英] Sending SMS using CTMessageCenter (iOS 7)

查看:163
本文介绍了使用CTMessageCenter发送短信(iOS 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用专用API以编程方式发送短信.我的手机没有越狱.

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 ?

推荐答案

我想,您必须使用E.123国际符号写出电话号码. 因此,添加加号和国家/地区代码.如果电话号码是USA,则将开头的0替换为+1:

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"];

对于斯里兰卡的电话号码,请使用相应的国家代码+94.

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

更新

我已经在iOS 7下测试了旧的可以正常工作的iOS 5代码... sendSMSWithText:serviceCenter:toAddress:返回NO. 使用新方法sendSMSWithText:serviceCenter:toAddress:withMoreToFollow:

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的建议似乎是正确的:-/

Panagiotis' suggestion seems correct :-/

更新2

https://stackoverflow.com/a/20425853/2270880 提供了正确的答案.

在iOS 7下,该应用需要两个权利com.apple.CommCenter.Messages-sendcom.apple.coretelephony.Identity.get.通过文件appname.entitlements添加其他权利(并在目标的Build Settings> All> Code Signing> Code Signing Entitlements中进行设置)会给您带来错误

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

在非越狱设备上.

这篇关于使用CTMessageCenter发送短信(iOS 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆