0

オブジェクトを NSData 形式で NSMutablearray に保存します。いいえ、電子メールの本文に添付しようとしています。コードは次のとおりです。

  - (IBAction)sendEmail
     {

   if ([MFMailComposeViewController canSendMail])
  {
       NSArray *recipients = [NSArray arrayWithObject:@"example@yahoo.com"];
       MFMailComposeViewController *controller = [[MFMailComposeViewController 
            alloc] init];
       controller.mailComposeDelegate = self;
       [controller setSubject:@"Iphone Game"];
       NSString *string = [viewArray componentsJoinedByString:@"\n"];
       NSString *emailBody = string; 
       NSLog(@"test=%@",emailBody);
       [controller setMessageBody:emailBody isHTML:YES];
       [controller setToRecipients:recipients];
       [self presentModalViewController:controller animated:YES];
       [controller release];
    }
else 
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" 
            message:@"Your device is not set up for email." delegate:self 
            cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];   
    [alert release];
}

 }

エラーは発生しませんが、電子メールにデータが表示されません。NSLog にこれが表示されます。 NSMutableArray データを電子メール本文に添付する方法..

4

3 に答える 3

2

あなたの質問がよくわかりません。この方法でデータを設定してみてください。composerに渡す前に、設定する値を確認し、

これを見る

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

    NSString *mSubject;

    if(isInvite)
    {
        mSubject=@"TAPP Invitation";
    }
    else 
    {
        mSubject= @"TAPP email";
    }

    [picker setSubject:mSubject];

    NSString *mBody;

    if(isInvite)
    {
        NSString *pTappId=[[DataModel sharedDataModel] getValueForKey:USER_TAPP_ID];
        NSString *currentUserName=[[DataModel sharedDataModel] getValueForKey:CURRENT_USER_NAME];
         mBody=[NSString stringWithFormat:@"<HTML><BODY>Hi,<br><br>We already know one another, and I would like us to keep in touch.<br><br>Let's connect through TAPP (<a href=\"http://download.mytapp.com\">Download Here</a>) a smarter, private way to exchange and manage contact information.<br><br>Join TAPP and secure your preferred, unique ID before it is too late, and then connect with me. My TAPP ID is %@.<br><br>For more information, <a href=\"http://www.mytapp.com\">click here</a><br><br>Regards,<br><br>%@</BODY></HTML>",pTappId,currentUserName];
    }
    else 
    {
        mBody= [NSString stringWithFormat:@"<HTML><BODY><br /><br />Connected by <a href=http://www.mytapp.com>TAPP</a></BODY></HTML>"];
    }

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:selectedEmailId]; 
    //NSArray *toRecipients = [NSArray arrayWithObject:@""]; 

    [picker setToRecipients:toRecipients];

    // Attach an image to the email
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];

    //NSData *myData = UIImagePNGRepresentation(photo.image);
    //[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"abc.png"];

    // Fill out the email body text
    NSString *emailBody = mBody;
    [picker setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:picker animated:YES];

    [picker release];
于 2012-05-07T10:59:49.523 に答える
1

標準の電子メール添付ファイルとしてデータを添付しようとしている場合は、これを使用します。

NSData *data = UIImageJPEGRepresentation(artworkImageView.image, 0.0);
[picker addAttachmentData:data mimeType:@"image/jpeg" fileName:@"Photo.jpeg"];

適切な MIME タイプとファイル名を指定するだけで、好きなようにdata指定できます。

于 2012-05-07T11:12:47.703 に答える
1

viewArray の定義が間違っているのではないでしょうか?

.h ファイル内:

@property(nonatomic, retain) NSMutableArray *viewArray;

.m ファイルで:

@synthesize viewArray;

メソッド「componentsJoindedByString」については、アップルのドキュメントを参照してください。よくわからないエラーが見つかりません。

APIからのviewArray初期化による私のテスト:(うまくいきます)

- (IBAction)sendEmail {

  self.viewArray = [NSArray arrayWithObjects:@"here", @"be", @"dragons", nil];

  if ([MFMailComposeViewController canSendMail])
  {
    NSArray *recipients = [NSArray arrayWithObject:@"example@yahoo.com"];
    MFMailComposeViewController *controller = [[MFMailComposeViewController 
                                            alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"Iphone Game"];

    //is anything in the array?
    NSLog(@"viewArray: %@", viewArray);

    NSString *string = [viewArray componentsJoinedByString:@"\n"];
    NSString *emailBody = string; 
    NSLog(@"test=%@",emailBody);
    [controller setMessageBody:emailBody isHTML:YES];
    [controller setToRecipients:recipients];
    [self presentModalViewController:controller animated:YES];
    [controller release];
  }
  else 
  { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" 
                                                message:@"Your device is not set up for     email." delegate:self 
                                      cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];   
    [alert release];
  } 
}
于 2012-05-07T11:54:55.470 に答える