以编程方式通过 Xcode 发送消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35125042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
send a message through Xcode programmatically
提问by Anup Gupta
I am trying to send a message through Xcodeprogrammatically but when I click the send button it opens the message sending box. But I want to send message directly without opening message box. Is this possible in iOS Xcode or not?Please help me.
我正在尝试以编程方式通过Xcode发送消息,但是当我单击发送按钮时,它会打开消息发送框。但是我想直接发送消息而不打开消息框。这在 iOS Xcode 中是否可行?请帮我。
but don't want open sending message box.
但不想打开发送消息框。
the code is
代码是
- (IBAction)sendSMS:(id)sender
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello this is anup";
controller.recipients = [NSArray arrayWithObjects:@"7026144009", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
{
NSLog(@"faild");
UIAlertController *alrt=[UIAlertController alertControllerWithTitle:@"my apps" message:@"unknown error" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//do something when click button
}];
[alrt addAction:okAction];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
回答by Anbu.Karthik
ya it is possibleon that your scenario no need of MFMessageComposeViewController
, just one webservice is enough, send the two (@"Hello this is anup",@"7026144009")
to your backend , the backend developer send the SMS
to that particular number using SMTP Server
option.
是的,您的场景可能不需要MFMessageComposeViewController
,只需一个网络服务就足够了,将两个发送(@"Hello this is anup",@"7026144009")
到您的后端,后端开发人员SMS
使用SMTP Server
选项将其发送到该特定号码。
Choice -2
选择-2
if you want to handle in your own use some thirdparty SDK like skpsmtpmessage, it work like same SMTP
.
如果你想自己处理一些第三方 SDK,比如skpsmtpmessage,它的工作原理是一样的SMTP
。
回答by Abhiranjan Chaurasia
You can't programatically send a message without the user's consent. The most you can do, is open the messages app and if the user decides to send it, he can send it.
未经用户同意,您不能以编程方式发送消息。您最多可以做的是打开消息应用程序,如果用户决定发送它,他可以发送它。
(IBAction)sendingMessage:(id)sender {
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"SMS message here";
controller.recipients = [NSArray arrayWithObjects:@"+919015156562", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
And:
和:
(void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result {
[self dismissViewControllerAnimated:YES completion:nil];
}
回答by Ankit Srivastava
You can't programatically send a message without the user's content. The most you can do is open the messages app and if the user decides to send it, he can send it.
您无法以编程方式发送没有用户内容的消息。您最多可以打开消息应用程序,如果用户决定发送,他可以发送。