MFMessageComposeViewController alloc returns nil

此生再无相见时 提交于 2019-11-30 11:10:30

Have you checked +[MFMessageComposeViewController canSendText]?

From the MFMessageComposeViewController Class Reference,

Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NO. If SMS delivery isn’t available, you can notify the user or simply disable the SMS features in your application.

Starting in iOS 5, you can register to be notified of changes to the availability of text message sending by way of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification.

Reasons it might be returning nil:

  • Device isn't running iOS 4.
  • Device is an iPod Touch/iPad without iMessage enabled.
  • No SIM card? (The view now shows in iOS 6; the app is not notified of the message send failure.)
  • "Device" is actually the simulator. (Perhaps this works in iOS 6 too.)

Similarly, [[MFMailComposeViewController alloc] init] returns nil when no mail accounts are enabled (you can quickly test this by disabling accounts in Settings), but also shows a "No mail accounts configured" alert for you. MFMessageComposeViewController does not do this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!