【问题标题】:send/receive data sms iOS programmatically以编程方式发送/接收数据短信 iOS
【发布时间】:2012-03-15 10:55:37
【问题描述】:

如何在iOS的特定端口发送和接收数据短信?

欢迎使用私有 API 解决方案。

【问题讨论】:

    标签: ios sms iphone-privateapi


    【解决方案1】:
    import 
    #import <MessageUI/MessageUI.h>
    
    
    <MFMessageComposeViewControllerDelegate,MFMailComposeViewControllerDelegate>
    
    
    
        -(void)send_SMS{
    
          Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
    
                if (messageClass != nil) {
                    // Check whether the current device is configured for sending SMS messages
                    if ([messageClass canSendText]) {
                        [self displaySMSComposerSheet];
                    }
                    else {
                      //  feedbackMsg.hidden = NO;
                      //  feedbackMsg.text = @"Device not configured to send SMS.";
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device not configured to send SMS." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call",nil];
                        //[alert setTag:5];
                        [alert show];
                    }
                }
                else {
                   // feedbackMsg.hidden = NO;
                   // feedbackMsg.text = @"Device not configured to send SMS.";
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device not configured to send SMS." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call",nil];
                    //[alert setTag:5];
                    [alert show];
    
                }
    
    
        }
    
    
    
    
    // Displays an SMS composition interface inside the application.
    -(void)displaySMSComposerSheet
    {
        MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
        picker.messageComposeDelegate = self;
        picker.body=@"Testing";
        picker.recipients = [NSArray arrayWithObject:@"12345678"];
        [self presentModalViewController:picker animated:YES];
        }
    
    
    
    // Dismisses the message composition interface when users tap Cancel or Send. Proceeds to update the
    // feedback message field with the result of the operation.
    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                     didFinishWithResult:(MessageComposeResult)result {
    
        feedbackMsg.hidden = NO;
        // Notifies users about errors associated with the interface
        switch (result)
        {
            case MessageComposeResultCancelled:{
                //feedbackMsg.text = @"Result: SMS sending canceled";
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS sending canceled" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
                break;
            case MessageComposeResultSent:{
                //feedbackMsg.text = @"Result: SMS sent";
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
                break;
            case MessageComposeResultFailed:{
                //feedbackMsg.text = @"Result: SMS sending failed";
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS sending failed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
                break;
            default:
            {
                //feedbackMsg.text = @"Result: SMS not sent";
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"SMS not sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
            }
                break;
        }
        [self dismissModalViewControllerAnimated:YES];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2011-11-16
      • 2014-05-09
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多