MFMailComposeViewController does not work in production

193 Views Asked by At

Any thoughts on why MFMailComposeViewController worked in development, but when I set my Cloudkit environment to production, the view controller won't even pop up? This seems strange, but I'm sure there's a reason why. The code that worked literally 5 minutes ago is below. The rest of the app works, and connects perfectly with the server.

CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];
CKRecordID *record = [[CKRecordID alloc] initWithRecordName:@"hidden for stackoverflow"];
[publicDatabase fetchRecordWithID:record completionHandler:^(CKRecord * record, NSError *error) {
    if (!error) {
        dispatch_async (dispatch_get_main_queue(), ^{
            feedbackNumber = record[@"RequestNumber"];

            NSString* number = record[@"RequestNumber"];
            int value = [number intValue] +1;
            record[@"RequestNumber"] = [NSString stringWithFormat:@"%d",value];
            [publicDatabase saveRecord:record completionHandler:^(CKRecord *savedRecord, NSError *saveError) {

                dispatch_sync(dispatch_get_main_queue(), ^{
                  NSString *emailTitle = [NSString stringWithFormat:@"%@%@%@", @"Request #", [NSString stringWithFormat:@"%d",value], @" - AssassinsX Immerse"];
                  NSString *messageBody = @"Please type your email below";

                  NSArray *toRecipents = [NSArray arrayWithObject:@"email here, hidden for stackoverflow"];

                  MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
                   mc.mailComposeDelegate = self;
                  [mc setSubject:emailTitle];
                  [mc setMessageBody:messageBody isHTML:NO];
                  [mc setToRecipients:toRecipents];

                   [self presentViewController:mc animated:YES completion:nil];

                });
            }];
        });
    }
}];
1

There are 1 best solutions below

0
On

Make Sure You Have Add Any of Your Mail Account in Your Device. Here Is The Code In Swift

import UIKit
import MessageUI
class ViewController: UIViewController,MFMailComposeViewControllerDelegate
{
   override func viewDidLoad() 
   {
      super.viewDidLoad()
      self.SendMail()
   }

   func SendMail()
   {
      let to = ["[email protected]"]
      let Subject = "Subject Here"
      let MessageBody = "Message Body"            
      let mc: MFMailComposeViewController = MFMailComposeViewController()
      mc.mailComposeDelegate = self
      mc.setSubject(Subject)
      mc.setMessageBody(MessageBody, isHTML: false)
      mc.setToRecipients(to)
      self.presentViewController(mc, animated: true, completion: nil)
   }
}