我很长时间以编程方式发送短信.它在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];
}
Run Code Online (Sandbox Code Playgroud)
我甚至发布了带有Deployment Target 5.1的最新Xcode 5.0的应用程序的新版本,因为我还需要支持iOS5.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];
}
Run Code Online (Sandbox Code Playgroud)