ios - 发送消息ios9后MFMessageComposeViewController未返回应用程序
<p><p>之前在 iOS7 上,我测试了我的 SMS 模块,它运行良好。更新iOS版本后,发现短信模块有问题。</p>
<p>在我的 .h 文件中</p>
<pre><code>#import <MessageUI/MFMessageComposeViewController.h>
@interface ViewController : UIViewController<UITextFieldDelegate,MFMessageComposeViewControllerDelegate>
</code></pre>
<p>在我的 .m 文件中</p>
<pre><code>- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [ init];
if()
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
;
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
if (result == MessageComposeResultCancelled){
NSLog(@"Message cancelled");
}
else if (result == MessageComposeResultSent){
NSLog(@"Message sent");
}
else{
NSLog(@"Message failed");
}
}
</code></pre>
<p>按发送后,日志中显示“已发送消息”,但 View 仍在消息屏幕上。我不知道为什么它不会回到我的应用程序。</p>
<p>需要帮助找出为什么它不会返回到我的应用程序的问题。</p>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您似乎没有在 <code>mailcomposer</code> 出现后将其关闭。您必须通过以下方法关闭呈现的 <code>MFMessageComposeViewController</code>:</p>
<pre><code>-(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");
}
; //<---- This line
}
</code></pre>
<p>此外,<code>- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated</code> 自 iOS 6 起已弃用。使用 <code>- (void)presentViewController:(UIViewController *)viewControllerToPresent动画:(BOOL)标志完成:(void (^)(void))completion</code> 而不是这样:</p>
<pre><code>;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 发送消息ios9后MFMessageComposeViewController未返回应用程序,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32687195/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32687195/
</a>
</p>
页:
[1]