`[[MFMailComposeViewController alloc] init]` returns nil when no email is set

Originator:bas
Number:rdar://33892951 Date Originated:August 15 2017, 11:10 AM
Status:open Resolved:
Product:iOS + SDK Product Version:iOS 10, iOS 11
Classification:Crash/Hang/Data Loss Reproducible:always
 
Area:
Something not on this list

Summary:
`[[MFMailComposeViewController alloc] init]` (or `MFMailComposeViewController()` in Swift) returns nil when no email is set. In Swift, the returned type is actually `MFMailComposeViewController`, not `MFMailComposeViewController?` or `MFMailComposeViewController!`, which can cause a crash when no email is set, without an option to prevent this.

Steps to Reproduce:
1. Initialize `MFMailComposeViewController`: `MFMailComposeViewController()`
2. Try printing the object either in lddb or directly: `print(MFMailComposeViewController())` or `po object`

Expected Results:
`MFMailComposeViewController()` should return a nil-object when no mail is set (and thus, should be nullable), and should print a warning telling the developer to call `MFMailComposeViewController.canSendMail()` before initializing the `MFMailComposeViewController`.

There should not be a `UIAlertController` being popped up by the framework, unless it is documented.

Observed Results:
iOS 10:

1. Accessing the object crashes the app, with lldb reporting `<uninitialized>` when inspecting the object.
2. An undocumented `UIAlertController` pops up (when not interacting with the object). See attached screenshot.

iOS 11:

1. Accessing the object *does not* the app, while lldb reports `<uninitialized>` when inspecting the object.
2. An undocumented `UIAlertController` pops up (when not interacting with the object). See attached screenshot.
3. Testing if the returned `MFMailComposeViewController` is nil (`MFMailComposeViewController() == nil`) returns `true`, while a warning shows up that says `Comparing non-optional value of type 'MFMailComposeViewController' to nil`.

Version:
iOS 10.3.1 (simulator), iOS 10.3.3 (device), iOS 11.0 (15A5341e, simulator)

Notes:


Configuration:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!