1

次のコードで電子メールを送信しようとしています — エラーは発生せず、電子メール クライアントは読み込まれますが、電子メールは送信されません。

- (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;'>&nbsp;&nbsp;X&nbsp;&nbsp;</td> </tr> </table> Start of Cycle,<table> <tr> <td style='border: solid 1px #f75fea; text-align: center;'>&nbsp;&nbsp;M&nbsp;&nbsp;</td> </tr> </table> Mild Pain, <table>  <tr> <td style='border: solid 1px #f75fea; text-align: center;'>&nbsp;&nbsp;S&nbsp;&nbsp;</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;'>&nbsp;%@&nbsp;</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;'>&nbsp;%@&nbsp;</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");

}
}

なぜこれが起こっているのか誰にもわかりますか?

4

1 に答える 1

1

コード内から送信イベントをキャプチャする必要があることに気付きました

そのような

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
于 2013-01-13T20:44:41.183 に答える