关于为什么MFMailComposeViewController在开发中工作的任何想法,但是当我将Cloudkit环境设置为生产时,视图控制器甚至不会弹出?这看起来很奇怪,但我确信这是有原因的。 5分钟前字面上的代码如下。应用程序的其余部分可以工作,并与服务器完美连接。
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];
});
}];
});
}
}];
答案 0 :(得分:-1)
确保您已在设备中添加任何邮件帐户。这是Swift中的代码
import UIKit
import MessageUI
class ViewController: UIViewController,MFMailComposeViewControllerDelegate
{
override func viewDidLoad()
{
super.viewDidLoad()
self.SendMail()
}
func SendMail()
{
let to = ["yourmail@gmail.com"]
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)
}
}