简体   繁体   English

在iOS7中发送短信 - 从iOS6升级后出现问题

[英]sending SMS in iOS7 - problems after upgrade from iOS6

I am sending SMS programmatically like this for a long time now. 我很长时间以编程方式发送短信。 It worked without any problems in iOS6. 它在iOS6中没有任何问题。

But now after update to iOS7 some users have probelms with the app. 但是现在在更新到iOS7后,一些用户对应用程序有疑问。 They need to deinstall the app - reboot the iPhone - reinstall it and then it works.Just reinstalling it without rebooting the phone does not work either. 他们需要卸载应用程序 - 重新启动iPhone - 重新安装它然后它工作。只需重新安装它而无需重新启动手机也无法正常工作。

What could be the reason for this really annoying problem? 这可能是什么原因导致这个真正烦人的问题?

Furthermore there are a few cases where they can send several SMS after this procedure but then the iPhone SMS-Dialog appears very slowly and no SMS is being sent again, until they restart the iPhone. 此外,在一些情况下,他们可以在此过程后发送几条短信,但随后iPhone短信对话显示非常缓慢,并且没有再次发送短信,直到他们重新启动iPhone。 Just stopping and restarting the app does not help. 只是停止并重新启动应用程序没有帮助。

Here's the normal SMS code: 这是正常的短信代码:

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

I even released a new Version of the app with the newest Xcode 5.0 with Deployment Target 5.1, since I need to support iOS5.1 users still. 我甚至发布了带有Deployment Target 5.1的最新Xcode 5.0的应用程序的新版本,因为我还需要支持iOS5.1用户。

There isn't enough information to tell what's causing the problem. 没有足够的信息来说明造成问题的原因。 Btw, why are you setting messageComposeDelegate twice? 顺便问一下,为什么要设置messageComposeDelegate两次?

This is apple's most recent sample code that I've modified worked on my own devices running iOS 7 and iOS 8. Make sure to import MessageUI.framework. 这是我最近修改的示例代码,我在自己的运行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];
}

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

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