1

전자 메일 본문에 NSMutableArray 데이터를 첨부하려고합니다. 내 viewArray는 전자 메일 body.here 내 E 메일 코드는이 viewArray를 부착 할 수있는 방법 그 때는 위에서 언급 이러한 모든 특성과 함께 3 UILabel의 포함 된 경우 이제NSMutableArray 데이터를 전자 메일 본문에 첨부하려면 어떻게합니까?

NSUserDefaults *defaults1 = [NSUserDefaults standardUserDefaults]; 
    NSString *msg1 = [defaults1 objectForKey:@"key5"]; 
    NSData *colorData = [defaults1 objectForKey:@"key6"]; 
    UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData]; 
    NSData *colorData1 = [defaults1 objectForKey:@"key7"]; 
    UIColor *color1 = [NSKeyedUnarchiver unarchiveObjectWithData:colorData1]; 
    NSData *colorData2 = [defaults1 objectForKey:@"key8"]; 
    UIFont *color2 = [NSKeyedUnarchiver unarchiveObjectWithData:colorData2]; 
    CGFloat x =(arc4random()%100)+100; 
    CGFloat y =(arc4random()%100)+250; 
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 100, 70)]; 
    lbl.userInteractionEnabled=YES; 
    lbl.text=msg1; 
    lbl.backgroundColor=color; 
    lbl.textColor=color1; 
    lbl.font =color2; 
    lbl.lineBreakMode = UILineBreakModeWordWrap; 
    lbl.numberOfLines = 50; 
    [self.view addSubview:lbl]; 
    [viewArray addObject:lbl ]; 

: 여기 내 NSMutableArray를 코드입니다.

- (IBAction)sendEmail 
    { 

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

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:viewArray]; 
    [controller addAttachmentData:data mimeType:@"application/octet-stream"; 
    fileName:nil]; 

    NSString *emailBody = @"Happy Valentine Day!"; 
    [controller setMessageBody:emailBody isHTML:NO 
    [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]; 
} 

} 

나는 이메일 body..which 어느 한 이메일 내 viewArray 데이터를 첨부 할 수있는 방법 나를 인도 viewArray.please에에 오류가있는 데이터를 참조하지 나누었다 얻었다.

답변

2

NSData가 전송되기 전에 nil이 아닌지 확인하십시오.

즉;

[controller setSubject:@"Iphone Game"]; 

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:viewArray]; 

if(!data){ 
    NSLog(@"Data is nil"); 

    return; 
} 
[controller addAttachmentData:data mimeType:@"application/octet-stream"; 
fileName:nil]; 
+0

응답을위한 Thanx. NSData는 브레이크 포인트를 사용할 때 바이트를 보여줍니다. 하지만 왜 내 viewArray 데이터가 전자 메일에 표시되지 않습니다 이해할 수 없습니다. 친애하는 가이드 어떻게 할 수 있습니다. – jamil

관련 문제