Sending SMS in iOS7 - problems after updating from iOS6

I send SMS programmatically so for a long time. It worked without any problems in iOS6.

But now, after upgrading to iOS7, some users have problems with the application. They must uninstall the application - restart the iPhone - reinstall it, and then it works. Just reinstalling it without restarting the phone also does not work.

What could be causing this really annoying problem?

In addition, there are several cases where they can send multiple SMSs after this procedure, but then the iPhone SMS-Dialog appears very slowly and no SMS is sent again until they restart the iPhone. Just terminating and restarting the application does not help.

Here is 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 application with the latest Xcode 5.0 with the goal of deploying 5.1, since I still need to support iOS5.1 users.

+6
source share
1 answer

There is not enough information to determine the cause of the problem. By the way, why are you setting messageComposeDelegate twice?

This is the most recent code example that I modified on my own device with iOS 7 and iOS 8. Be 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]; } 
0
source

Source: https://habr.com/ru/post/956400/


All Articles