我正在尝试使用以下代码发送电子邮件 - 我没有收到任何错误,并且电子邮件客户端将加载,但它不会发送电子邮件:
- (IBAction)emailButtonPressed {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSString *docsDir;
NSArray *dirPaths;
sqlite3_stmt *statement;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"ral.db"]];
const char *dbpath = [databasePath UTF8String];
self.html = [NSMutableString stringWithFormat:@"<html><head></head><body>Key: <table> <tr> <td style='border: solid 1px #f75fea; text-align: center; background-color: #ed9ce6;'> X </td> </tr> </table> Start of Cycle,<table> <tr> <td style='border: solid 1px #f75fea; text-align: center;'> M </td> </tr> </table> Mild Pain, <table> <tr> <td style='border: solid 1px #f75fea; text-align: center;'> S </td> </tr> </table> Severe Pain<br/><br/><br/><table><tr>"];
int i = 0;
if (sqlite3_open(dbpath, &ral) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat: @"SELECT * from DIARY order by _id"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(ral, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
if ((i == 14) || (i == 28) || (i == 42) || (i == 56) || (i == 70) || (i == 84) || (i == 98) || (i == 112)) {
[self.html appendString:@" </tr> <tr> "];
}
//create an image view
NSMutableString *timeStamp = [[NSMutableString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
NSString *timeStamp_ = [[NSString stringWithFormat:@"%@", timeStamp] substringToIndex:5];
NSMutableString *periodStart = [[NSMutableString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];
NSMutableString *painValue = [[NSMutableString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)];
[self.html appendString:[NSString stringWithFormat:@" <td> <table> <tr> <td style='font-family: arial; color:#777;'> %@ </td> </tr> ", timeStamp_]];
[self.html appendString:[NSString stringWithFormat:@"<tr> <td style='border: solid 1px #f75fea; text-align: center; background-color: #ed9ce6; width: 20px; height: 20px;font-family: arial; color:#333;'> %@ </td> </tr> ", periodStart]];
[self.html appendString:[NSString stringWithFormat:@"<tr> <td style='border: solid 1px #f75fea; text-align: center; width: 20px; height: 20px;font-family: arial; color:#333;'> %@ </td> </tr> </table> </td>", painValue]];
i = i + 1;
}
sqlite3_finalize(statement);
}
sqlite3_close(ral);
}
[self.html appendString:@"</table></body></html>"];
NSString *tempHtml = self.html;
[controller setSubject:@"Pain diary"];
[controller setMessageBody:[NSString stringWithFormat: @"%@", tempHtml] isHTML:YES];
// Show email view
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail]) {
[self presentModalViewController:controller animated:YES];
} else {
//do something
NSLog(@"cant send mail");
}
} else {
//do something
NSLog(@"class not instantiated");
}
}
有人能看出为什么会这样吗?
答案 0 :(得分:1)
我意识到我需要从我的代码中捕获发送事件
就是这样
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}