Checking That Mail Is Configured and the Internet Is Available

Listing 4.6 shows the code that performs both checks. You can replace the direct call to displayComposerSheet in tapButton with this code, which incorporates the necessary checks before it either calls displayComposerSheet or posts an alert. This code is based on the MessageComposer sample app.

Listing 4.6 Checking That Mail Is Configured and Available

- (IBAction)tapButton:(id)sender {                                       //1  NSLog (@" %@", _userTextView.text);  Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));  if (mailClass != nil)                                                  //2  {    // We must always check whether the ...

Get Learning iCloud Data Management: A Hands-On Guide to Structuring Data for iOS and OS X now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.