2009-12-04 94 views
1

我已通過iPhone應用程序發送附件。附件不會顯示在通過iPhone發送的郵件中

但是,當我看到郵件時,我可以看到顯示附加內容的upin。

但是,當我打開郵件,我找不到任何附件?

這背後有什麼問題?

有沒有人遇到同樣的問題?

在此先感謝您分享您的寶貴知識。

-(IBAction)btnPressedExport:(id)sender{ 

    NSArray *x=[[NSArray alloc] initWithArray:[DatabaseAccess getAllTransactionsForUserID:[BudgetTrackerAppDelegate getUserID] profileID:[BudgetTrackerAppDelegate getProfileID]]]; 
    int i=-1,j=[x count]; 
    NSDictionary *tmp; 
    NSMutableString *stringToWrite=[[NSMutableString alloc] init]; 
    for(;i<j;i++){ 
     if(i==-1){ 
      [stringToWrite appendString:@"TransactionID,TransactionDate,ProfileName,ProfileType,GroupName,GroupType,CategoryName,TransactionAmt\n"]; 
     } else { 
      tmp=[x objectAtIndex:i]; 
      [stringToWrite appendFormat:@"%@,%@,%@,%@,%@,%@,%@,%@\n", 
      [tmp valueForKey:@"TraID"],[tmp valueForKey:@"TraDate"],[tmp valueForKey:@"ProfileName"],[tmp valueForKey:@"ProfileType"],[tmp valueForKey:@"GroupName"],[tmp valueForKey:@"GroupType"],[tmp valueForKey:@"CatName"],[tmp valueForKey:@"TraAmt"]]; 
     } 
    } 
    [stringToWrite writeToFile:[self pathOfCSVForExport] atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil]; 
// [stringToWrite writeToFile:[self pathOfCSVForExport] atomically:YES]; 


    picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate=self; 
// picker.delegate=self; 

    [picker setSubject:@"Hello from Sugar!"]; 


    //Set up recipients 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
// NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
// NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

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

    // Attach an image to the email 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"myExport" ofType:@"csv"]; 
    NSData *myData = [NSData dataWithContentsOfFile:path]; 

    NSString *[email protected]"BudgetTracker.csv";//[NSString stringWithFormat:@"%@.csv",[x valueForKey:@"ProfileName"]]; 

    [picker addAttachmentData:myData mimeType:@"text/plain" fileName:fileNameToSend]; 
    // text/html/ 
    // Fill out the email body text 
    NSString *emailBody = [NSString stringWithFormat:@"%@",@"Hello! This is export test."]; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    [self presentModalViewController:picker animated:YES]; 

} 

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ 
// NSLog(@"here2"); 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: break; 
     case MFMailComposeResultSaved: break; 
     case MFMailComposeResultSent: break; 
     case MFMailComposeResultFailed: break; 
     default: break; 
    } 
// self.navigationController.navigationBarHidden=NO; 
// [self becomeFirstResponder]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

的路徑是它支持的附件類型? – bpapa 2009-12-04 17:46:58

+0

是的!我見過很多應用程序使用這個擴展。 – 2009-12-04 17:48:18

+0

你能顯示你用來發送的代碼嗎?如果您向郵件發送的郵件與郵件具有相同的附件,它會顯示出來嗎? – 2009-12-04 17:57:52

回答

3

這看起來錯,除非它只是用於測試:

// Attach an image to the email 
NSString *path = [[NSBundle mainBundle] pathForResource:@"myExport" ofType:@"csv"]; 
NSData *myData = [NSData dataWithContentsOfFile:path]; 

您使用的路徑是在您的應用程序包文件時,它是隻讀的,所以它不能成爲您剛剛製作的CSV文件。

,如果你想要寫一個臨時文件和電子郵件,你需要把它寫在某處喜歡你的文檔目錄,即像

NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *docDirectory = [sysPaths objectAtIndex:0]; 
NSString *filePath = [NSString stringWithFormat:@"%@/myexport.csv", docDirectory]; 
相關問題