iOS8中的MFMessageComposeViewController问题 [英] MFMessageComposeViewController issues in iOS8

查看:163
本文介绍了iOS8中的MFMessageComposeViewController问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS8中遇到了MFMessageComposeViewController的一个奇怪的错误,它只能在我自己的应用程序中重现。它正在App Store中影响应用程序,使用iOS8上运行的iOS7 SDK以及我自己的测试设备(iPhone和iPad)中的iOS8 SDK构建

I've run into a strange bug with MFMessageComposeViewController in iOS8, that is only reproducible within my own app. It's affecting the app right now in the App Store, built with the iOS7 SDK running on iOS8, as well with the iOS8 SDK in my own test devices (iPhone and iPad)

问题是,当我调出MFMessageComposeViewController时,它会向我显示没有文本字段或发送按钮的控制器。我没有在iOS7和iOS8之间更改我的代码,因此不确定为什么会发生这种情况。代码本身非常简单:

The issue is that when I bring up the MFMessageComposeViewController, it shows me the controller without a text field or a Send button anymore. I haven't changed my code between iOS7 and iOS8, so not sure why this is happening. The code itself is very simple:

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
[picker setRecipients: @[@"5551112222"]];
[picker setBody: @"Test"];

[self presentViewController:picker animated:YES completion: ^{
    NSLog(@"MFMessageComposeViewController completion handler"); 
}];

这就是它的样子:

任何想法我可以尝试一种解决方法吗?我已经尝试在完成处理程序中设置textField和recipients;尝试在最顶层的视图控制器上调用becomeFirstResponder;没有运气。再次,这在iOS7中完全正常。

Any ideas for what I can try for a work-around? I've tried setting the textField and recipients in the completion handler; tried calling becomeFirstResponder on the top-most view controller; no luck. Again, this was/is working perfectly fine in iOS7.

编辑:

所以我找到了Apple自己的样本此链接中 MFMessageComposeViewController 的代码: https://developer.apple.com/library/ios/samplecode/MessageComposer/Listings/MessageComposerViewController_m.html

So I found Apple's own sample code for MFMessageComposeViewController from this link: https://developer.apple.com/library/ios/samplecode/MessageComposer/Listings/MessageComposerViewController_m.html

当我构建并运行此应用程序, MFMessageComposeViewController 完美显示,预填充电话号码和文本字段也可以。但是当我将他们的文件复制到我的应用程序中时,将他们的故事板作为我的主要故事板,按下撰写短信按钮,我看到同样的问题!

When I build and run this app, the MFMessageComposeViewController shows up perfectly, and pre-filling the phone number and text fields works as well. But when I copy their files into my app, make their storyboard my main storyboard, press the "Compose SMS" button and I see the same exact problem!

这里发生了什么?很困惑。可能是我自己的应用程序中的一些配置阻止消息编写器正确显示?

What is going on here? Very confused. Could it be some configuration in my own app that is preventing the message composer from displaying correctly?

推荐答案

最后,在拆除我的大部分应用后,我能够找出问题所在。事实证明,我在一个类别中覆盖了一个UIViewController系统方法(而不是子类):

Finally, after tearing down most of my app, I was able to figure out the issue. Turns out, I was overriding a UIViewController system method in a category (instead of sub-classing):

@implementation UIViewController (UIViewController_Additions)
-(BOOL)canBecomeFirstResponder {
    return YES;
}

在iOS7之前一直运行正常,但iOS8内部必须有所改变和`MFMessageComposeViewController。一个4岁的黑客来咬你的屁股的案例

This has been working fine till iOS7, but something must have changed internally in iOS8 and `MFMessageComposeViewController. A case of the "4-year-old-hack coming to bite you in the ass"

根据这个链接,苹果也不鼓励这种做法(虽然我找不到最初的Apple源代码: https://stackoverflow.com/a/14259595/145552

This practice is discouraged by Apple as well, according to this link (though I couldn't find the original Apple source): https://stackoverflow.com/a/14259595/145552

这篇关于iOS8中的MFMessageComposeViewController问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆