简体   繁体   English

以编程方式通过Xcode发送消息

[英]send a message through Xcode programmatically

I am trying to send a message through Xcode programmatically but when I click the send button it opens the message sending box. 我试图以编程方式通过Xcode发送消息,但是当我单击发送按钮时,它会打开消息发送框。 But I want to send message directly without opening message box. 但是我想直接发送消息而不打开消息框。 Is this possible in iOS Xcode or not? iOS Xcode是否可能? Please help me. 请帮我。 这是发送按钮

当我单击发送按钮时,这是打开的发送消息框

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

ya it is possible on 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 ,只需一个web服务就足够了,将两个(@"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相同。

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. 您最多可以做的是打开消息应用程序,如果用户决定发送它,则可以发送它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM