【问题标题】:iphone email attachmentiphone电子邮件附件
【发布时间】:2010-11-26 06:07:28
【问题描述】:

我使用 MessageUI 框架 从我的应用程序发送带有附件的邮件。 但是我得到了以下错误,

2009-09-07 19:52:23.483 emailTest[11711:5b17]
 Error loading /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): Library not loaded: /System/Library/PrivateFrameworks/MobileWirelessSync.framework/MobileWirelessSync

 Referenced from: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator

      Reason: image not found

2009-09-07 19:52:23.489 emailTest[11711:5b17] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
[Switching to process 11711 local thread 0xf03]

我的代码是,

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[picker setSubject:@"This is iPhone email   attachment test"];

UIImage *sampleImg = [UIImage imageNamed:@"iPhone.jpg"];
NSData *imageData = UIImageJPEGRepresentation(sampleImg, 1);
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"iPhone.jpg"];


NSString *emailBody = @"I am sending the image attachment with iPhone email service";
[picker setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:picker animated:YES];
[picker release];

请帮帮我。

【问题讨论】:

  • 更具体 - 您正在运行什么代码来创建附件?要分离消息?您究竟是如何“使用 MessageUI 框架”的?
  • 请看代码。
  • 嗨,你的代码工作了吗?触摸电子邮件中的发送按钮时,我也收到了相同的消息。但是,我没有在邮件中添加任何附件。当我触摸取消按钮时,我无法关闭邮件控制器。我正在将邮件控制器添加到 cocos2d 层。请提供任何帮助。谢谢。

标签: iphone objective-c email mfmailcomposer


【解决方案1】:

您不必在文件名中输入扩展名。像“iphone.jpg”不起作用。只需在文件名中写入“iphone”,因为您已经定义了 mimeType。而且您还必须定义资源的路径。

以下是在邮件中附加“rainy.png”文件的示例代码。

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Hello"];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];  
[picker setBccRecipients:bccRecipients];

// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"It is raining";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];

【讨论】:

    【解决方案2】:

    此错误似乎与模拟器中正在运行的邮件有关,而不是与您的代码有关。甚至库存 Apple 的示例 MailComposer 在模拟器中也报告了相同的错误:

    2009-11-12 20:30:39.270 MailComposer[7426:4f1f] Error loading /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): Library not loaded: /System/Library/PrivateFrameworks/MobileWirelessSync.framework/MobileWirelessSync
      Referenced from: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator
      Reason: image not found
    2009-11-12 20:30:39.271 MailComposer[7426:4f1f] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
    

    【讨论】:

    • 嗨,我在日志中得到了同样的结果。当我触摸邮件控制器中的关闭或发送按钮时。我正在将邮件控制器添加到 cocos2d 层。而且我没有得到“在模拟器中运行邮件而不是在您的代码中运行邮件”。它是什么 ?我们可以改变它吗?谢谢。
    【解决方案3】:

    添加以下方法来关闭 MFMailComposeViewController:

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:   (MFailComposeResult)result error:(NSError*)error
    
     {
     // NEVER REACHES THIS PLACE
     [self dismissModalViewControllerAnimated:YES];
    
     NSLog (@"mail finished");
     }
    

    【讨论】:

    • 好点,但这可能不是这里的问题......顺便说一句,应该是MFMailComposeResult而不是MFailComposeResult
    【解决方案4】:

    将此用于在邮件中附加图像,在 ios 4、5、6 中测试

        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        UIImage *myImage = [UIImage imageNamed:@"image.png"];
        NSData *imageData = UIImagePNGRepresentation(myImage);
        [mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"image"];
    

    【讨论】:

      猜你喜欢
      • 2016-11-30
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 1970-01-01
      • 2015-12-26
      • 2020-09-04
      • 1970-01-01
      相关资源
      最近更新 更多