[英]Not receiving e-mail sent by an iPad app?
我有以下問題:
我試圖將文件附加到郵件中,並通過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];
}
我認為我的代碼不錯,但似乎不是。
請看一下。
提前致謝。
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"]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.