6

我现在以这样的方式以编程方式发送 SMS 很长一段时间了。它在iOS6中没有任何问题。

但是现在更新到 iOS7 后,一些用户对该应用程序有疑问。他们需要卸载应用程序 - 重新启动 iPhone - 重新安装它然后它就可以工作了。只需重新安装它而不重新启动手机也不起作用。

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

此外,在某些情况下,他们可以在此过程之后发送几条短信,但 iPhone SMS-Dialog 出现的速度非常慢,并且没有再次发送短信,直到他们重新启动 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];
}

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

4

1 回答 1

0

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

这是我在运行 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];
}
于 2014-08-15T22:19:32.590 回答