简体   繁体   中英

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.

But now after update to iOS7 some users have probelms with the app. 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.

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. 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.

There isn't enough information to tell what's causing the problem. Btw, why are you setting messageComposeDelegate twice?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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