2013-05-17 52 views
0

我有以下问题:未收到iPad应用程序发送的电子邮件?

我想附加一个文件邮件并通过邮件发送它在我的iPad应用程序。我认为一切顺利,日志输出表示邮件已发送,但我没有收到。

我尝试了一切,但仍然无法解决问题。

这里是我的代码,请看看,并告诉我,如果有什么奇怪或错误:

-(void)createCSVFile 
{ 
    NSMutableString *csv = [NSMutableString stringWithString:@"UniqueID,playerNumber,DateAndHour,Prize"]; 

    NSUInteger counter = [playerNumber count]; 
    NSLog (@"%d", counter); 
    // provided all arrays are of the same length 
    for (NSUInteger i=0; i < counter; i++) 
    { 
     [csv appendFormat:@"\n%@,%d,%@,%@", 
     [uniqueID objectAtIndex:i], 
     [[playerNumber objectAtIndex:i] intValue], 
     [dateAndHour objectAtIndex:i], 
     [prizeWon objectAtIndex:i] 
     ]; 
    //  NSLog (@"%@, %d, %@, %@", [uniqueID objectAtIndex:i], [[playerNumber objectAtIndex:i]intValue], [dateAndHour objectAtIndex:i], [prizeWon objectAtIndex:i]); 
     // instead of integerValue may be used intValue or other, it depends how array was created 
    } 

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

    NSString *outputFileName = [docDirectory stringByAppendingPathComponent:@"VictoryStats.csv"]; 

    NSError *error; 
    BOOL res = [csv writeToFile:outputFileName atomically:YES encoding:NSUTF8StringEncoding error:&error]; 

    if (res) 
    { 
     NSLog (@"created"); 
    } 

    if (!res) { 
     NSLog(@"Error %@ while writing to file %@", [error localizedDescription], outputFileName); 
    } 
} 


-(void)sendMail 
{ 
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 
    mailer.mailComposeDelegate = self; 
    [mailer setSubject:@"CSV File"]; 
    [mailer addAttachmentData:[NSData dataWithContentsOfFile:filePath] 
        mimeType:@"text/csv" 
        fileName:@"VictoryStats.csv"]; 
    [self presentViewController:mailer animated:YES completion:NULL]; 

} 

我觉得我的代码是好的,但看起来事实并非如此。

请看看。

在此先感谢。

+0

是你在设备还是模拟器测试?而电子邮件窗口打开你看到csv文件被检测到。 –

+1

请检查您的iPad设备中的代码,我认为它会起作用。 –

+0

我做到了。我在iPad上运行应用程序,发送邮件,但没有收到它。是的,我看到附加的CSV文件。我不知道发生了什么。 – scourGINHO

回答

0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docDir = [paths objectAtIndex:0]; 

    NSString *filename = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Product.csv"]]; 
    NSError *error = NULL; 
    BOOL written = [csvstr writeToFile:filename atomically:YES encoding:NSUTF8StringEncoding error:&error]; 
    if (!written) 
     NSLog(@"write failed, error=%@", error); 

    //CSV File 
    NSData *myData = [NSData dataWithContentsOfFile:[docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Product.csv"]]]; 
    [mail addAttachmentData:myData mimeType:@"text/csv" fileName:[NSString stringWithFormat:@"Product.csv"]]; 
+0

我没有改变任何东西,现在可以工作。似乎这是一个错误或类似的东西..现在我有另一个问题。因为我使用西里尔字(不是拉丁字母)填充.csv文件,所以当我在Excel中打开它时,它会显示符号而不是字母。哪里不对?我想它与编码有关。我已经将它设置为NSUTF8StringEncoding。 – scourGINHO

相关问题