2009-12-04 4 views
1

J'ai envoyé une pièce jointe via l'application iPhone. Mais quand je vois le courrier, je peux voir le message qui montre que quelque chose est attaché. Mais quand j'ai ouvert le courrier, je n'ai trouvé aucune pièce jointe?pièce jointe ne s'affiche pas dans le courrier qui est envoyé via l'iPhone

Quel est le problème derrière cela?

Est-ce que quelqu'un a déjà fait face au même type de problème?

Merci d'avance de partager vos connaissances.

-(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

Est-ce un type de pièce jointe pris en charge? – bpapa

+0

Oui! J'ai vu beaucoup d'application fonctionnant avec cette extension. –

+0

pouvez-vous montrer le code que vous utilisez pour envoyer? Si vous vous envoyez un e-mail avec la même pièce jointe par courrier, est-ce qu'il apparaît? –

Répondre

3

Cela semble mauvais, à moins qu'il est juste pour le test:

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

le chemin que vous utilisez est un fichier dans votre paquet d'application, qui est en lecture seule, donc il ne peut pas être le fichier CSV que vous venez de faire.

si vous voulez écrire un fichier temporaire et l'envoyer par courriel, vous devez écrire à un endroit comme votre répertoire de documents, à savoir un chemin comme

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