English 中文(简体)
数据附在电子邮件中?
原标题:Data Attached in E-mail?

我的NSMutable Array数据在NSData供囚犯使用。 我试图将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 ];

观点是我的NSMutable Array。 用于Array的所有数据储存都在NSData供囚犯使用。 我试图把Array数据附在电子邮件中。

   - (IBAction)sendEmail {
          if ([MFMailComposeViewController canSendMail])
      {
     NSArray *recipients = [NSArray arrayWithObject:@"[email protected]"];
    MFMailComposeViewController *controller = [[MFMailComposeViewController 
                                        alloc] init];
     controller.mailComposeDelegate = self;
     [controller setSubject:@"Iphone Game"];
     NSLog(@"viewArray: %@", viewArray);
     NSString *string = [viewArray componentsJoinedByString:@"
"];
     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];
 } 
 }

Here i see objects store in viewArray.in console its look like this..[2012-05-07 18:48:00.065 Note List[279:207] test=UILabel: 0x8250850; frame = (140 341; 56 19); text = Xxxxxxx ; clipsToBounds = YES; layer = > but in E-mail i see only this..>> please suggest any one how can i attached my viewArray data in E-mail. ]

最佳回答

在电子邮件附录中,你只能寄送NSData,或送上电子邮件,现在如果你想通过扼杀而发送,那么,你想要寄送电子邮件的所有价值,例如,可装读书。 页: 1 甲型六氯环己烷,有适当的钥匙,并存放在那里的身体和教区,另外还找到某种方式将你的物体转换为NSData,并用mfmailcomposer附上数据方法。

read this to convert NSArray into NSData

如何将NSArray改为NSData?

并将NSData改为NSArray

• 如何将NSData改为NSArray?

然后将这些数据编成册。

-(void)writeDataToFile:(NSString*)filename
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    if(filename==nil)
    {
        DLog(@"FILE NAME IS NIL");
        return;
    }
    // the path to write file
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat: @"%@",filename]];
    /*NSData *writeData;
     writeData=[NSKeyedArchiver archivedDataWithRootObject:pArray]; */
    NSFileManager *fm=[NSFileManager defaultManager];
    if(!filePath)
    {
        //DLog(@"File %@ doesn t exist, so we create it", filePath);
        [fm createFileAtPath:filePath contents:self.mRespData attributes:nil];
    }
    else 
    {
        //DLog(@"file exists");
        [self.mRespData writeToFile:filePath atomically:YES];
    }

    NSMutableData *resData = [[NSMutableData alloc] init];
    self.mRespData=resData;
    [resData release];
}

并最后附在电子邮件上

- (void)addAttachmentData:(NSData *)attachment mimeType:(NSString *)mimeType fileName:(NSString *)filename
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签