在iOS 7中发送短信 - 从iOS 6升级后出现问题

时间:2013-10-21 09:56:19

标签: iphone sms ios7

我很长时间以编程方式发送短信。它在iOS6中没有任何问题。

但是现在在更新到iOS7后,一些用户对该应用程序产生了疑问。他们需要卸载应用程序 - 重新启动iPhone - 重新安装它然后它工作。只需重新安装它而无需重新启动手机也无法正常工作。

这可能是什么原因导致这个真正烦人的问题?

此外,在某些情况下,他们可以在此过程后发送多条短信,但之后iPhone短信对话显得非常缓慢,并且没有再次发送短信,直到他们重启iPhone。只是停止并重新启动应用程序无济于事。

这是正常的短信代码:

MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
[messageVC setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {

    NSString *smsString = [NSString stringWithFormat:@"bla bla bla"];
    messageVC.body = smsString;
    messageVC.recipients = @[userPhone];
    messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
}

我甚至发布了带有Deployment Target 5.1的最新Xcode 5.0的应用程序的新版本,因为我还需要支持iOS5.1用户。

1 个答案:

答案 0 :(得分:0)

没有足够的信息来说明造成问题的原因。顺便问一下,你为什么要两次设置messageComposeDelegate?

这是我最近修改的Apple最新示例代码在我自己的运行iOS 7和iOS 8的设备上运行。确保导入MessageUI.framework。

/* -------------------------------------------------------------------------------
    showSMSPicker:
    IBAction for the Compose SMS button. 
   ------------------------------------------------------------------------------- */
- (IBAction)showSMSPicker:(id)sender
{
    /* Checks that the current device can send SMS messages. If no, [[MFMessageComposeViewController alloc] init] will return nil and the app will
     crash when -presentViewController:animated:completion: is called with a nil view controller */

    if ([MFMessageComposeViewController canSendText])
        // The device can send email.
    {
        [self displaySMSComposerSheet];
    }
    else
        // The device can not send email.
    {
        self.feedbackMsg.hidden = NO;
        self.feedbackMsg.text = @"Device not configured to send SMS.";
    }
}


/* -------------------------------------------------------------------------------
    displayMailComposerSheet
    Displays an SMS composition interface inside the application.
   ------------------------------------------------------------------------------- */

- (void)displaySMSComposerSheet
{
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;

    /*  One or more preconfigured recipients can be specified. The user has the option to remove 
     or add recipients from the message composer view controller */
    /* picker.recipients = @[@"Phone number here"]; */

    // Message body
    picker.body = @"This is a message about how great this app is. Please download it by clicking on the link below.";

    [self presentViewController:picker animated:YES completion:nil];
}

/* -------------------------------------------------------------------------------
    messageComposeViewController:didFinishWithResult:
    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
{
    self.feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MessageComposeResultCancelled:
            self.feedbackMsg.text = @"Result: SMS sending canceled";
            break;
        case MessageComposeResultSent:
            self.feedbackMsg.text = @"Result: SMS sent";
            break;
        case MessageComposeResultFailed:
            self.feedbackMsg.text = @"Result: SMS sending failed";
            break;
        default:
            self.feedbackMsg.text = @"Result: SMS not sent";
            break;
    }

    [self dismissViewControllerAnimated:YES completion:NULL];
}