Ich versuche eine E-Mail von meiner App zu senden. Wenn das Fenster zum Senden von E-Mails geöffnet wird, werden die Empfänger und der Hauptteil nicht festgelegt. Jedes Mal, wenn ich versuche, auf eines der Felder drücken sie meine App abstürzt, zu bearbeiten und gibt mir diese Fehlermeldung:MFMailComposeViewController funktioniert nicht
***Assertion failure in -[UIKeyboardTaskQueue waituntilalltasksarefinished], /sourcuecache/UIKIt_Sim/UIKit-3318.16.14/KeyboardTaskQueue.m:374 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!
Ich habe an den E-Mail-Tutorials angesehen und ich kann nicht finden, was ich falsch mache. Code hinzugefügt Referenz:
if ([MFMailComposeViewController canSendMail]) {
// Get current date/time
NSDate *date = picker.date;
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc]init];
mailer.mailComposeDelegate = self;
mailer.modalPresentationStyle = UIModalPresentationCurrentContext;
// Set title
NSDateFormatter *dateFmt = [[NSDateFormatter alloc] init];
[dateFmt setDateStyle:NSDateFormatterMediumStyle];
[mailer setSubject:[NSString stringWithFormat:@"test email: sent on %@", [dateFmt stringFromDate:date]]];
// Set recipient
[mailer setToRecipients:@[@"[email protected]"]];
// Set attachment
CGRect r = CGRectMake(0, 0, 200, 200);
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(r.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(r.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), - mapview.center.x + r.size.width/2.f, - mapview.center.y + r.size.height/2.f);
[mapholder.layer renderInContext:c];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(img);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"map"];
// Set email body
[dateFmt setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
CLLocationCoordinate2D loc = mapview.centerCoordinate;
NSString *emailBody = [NSString stringWithFormat:@"BRO it is Time: %@\n Location: %f,%f", [dateFmt stringFromDate:date], loc.latitude, loc.longitude];
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
und
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
es läuft in der Hauptsache – pudm