发送消息后 MFMessageComposeViewController 未返回到应用程序 ios9
MFMessageComposeViewController not returning to application after send message ios9
之前在 iOS7,我测试了我的 SMS 模块,它运行良好。更新iOS版本后,发现短信模块有问题
在我的 .h 文件中
#import <MessageUI/MFMessageComposeViewController.h>
@interface ViewController : UIViewController<UITextFieldDelegate,MFMessageComposeViewControllerDelegate>
在我的 .m 文件中
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled){
NSLog(@"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(@"Message sent");
}
else{
NSLog(@"Message failed");
}
}
按发送后,日志中显示"Message sent",但视图仍在消息屏幕上。我不知道为什么它不会返回到我的应用程序。
需要帮助找出为什么它不会返回到我的应用程序的问题。
提前致谢。
看来您并没有在 mailcomposer
出现后将其忽略。您将不得不通过以下方法关闭显示的 MFMessageComposeViewController
:
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MessageComposeResultCancelled){
NSLog(@"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(@"Message sent");
}
else{
NSLog(@"Message failed");
}
[self dismissViewControllerAnimated:YES completion:nil]; //<---- This line
}
此外,- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
已弃用,因为 iOS 6. 像这样使用 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion
:
[self presentViewController:mailComposer animated:YES completion:nil];
之前在 iOS7,我测试了我的 SMS 模块,它运行良好。更新iOS版本后,发现短信模块有问题
在我的 .h 文件中
#import <MessageUI/MFMessageComposeViewController.h>
@interface ViewController : UIViewController<UITextFieldDelegate,MFMessageComposeViewControllerDelegate>
在我的 .m 文件中
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled){
NSLog(@"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(@"Message sent");
}
else{
NSLog(@"Message failed");
}
}
按发送后,日志中显示"Message sent",但视图仍在消息屏幕上。我不知道为什么它不会返回到我的应用程序。
需要帮助找出为什么它不会返回到我的应用程序的问题。
提前致谢。
看来您并没有在 mailcomposer
出现后将其忽略。您将不得不通过以下方法关闭显示的 MFMessageComposeViewController
:
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MessageComposeResultCancelled){
NSLog(@"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(@"Message sent");
}
else{
NSLog(@"Message failed");
}
[self dismissViewControllerAnimated:YES completion:nil]; //<---- This line
}
此外,- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
已弃用,因为 iOS 6. 像这样使用 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion
:
[self presentViewController:mailComposer animated:YES completion:nil];