2013-04-25 74 views
1

如何通過ios系統中的代碼調用電子郵件應用程序?我想檢查電子郵件界面而不是發送郵件界面。如何調用電子郵件應用程序?

謝謝。

+0

兩者是完全不同的問題你的意思可能是重複的?只是懶得讀完整的問題 – 2013-04-25 04:57:18

回答

0

MFMailComposeViewController是一個官方API,您可以使用它從012應用程序中使用撰寫消息。

I've heard you can use the "mailto:" URL scheme to open the Mail application並從那裏撰寫郵件(假設郵件應用程序仍然安裝在您的iOS設備上),但這隻適用於從郵件應用程序撰寫郵件,它不會切換用戶到收件箱。

+0

是的,你是對的。但我需要調用電子郵件應用程序,而不是從郵件應用程序中編寫消息。你能幫我嗎? – user2297463 2013-04-25 05:33:28

1

你可以利用這個:

- (void)launchMailAppOnDevice 
{ 
    NSMutableString *subject = [NSMutableString string]; 
    [subject appendString:@"Your Subject"]; 

    NSMutableString *mailbody = [NSMutableString string]; 
    [mailbody appendString:@"Blah Blah Blah"]; 
    [mailbody appendString:@"Blah Blah Blah "]; 

    NSString *recipients = [NSString stringWithFormat:@"mailto:[email protected]?&subject=%@!",subject]; 

    NSString *body = [NSString stringWithFormat:@"&body=%@!",mailbody];; 

    NSString *emailString = [NSString stringWithFormat:@"%@%@", recipients, body]; 

    emailString = [emailString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 
} 

如果你想檢查郵件應用程序是否存在INT應用程序,你要打開它。

if ([[UIApplication sharedApplication] canOpenURL:[ NSURL URLWithString:@"mailto:"]]) 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:"]]; 
+0

我想查看郵件界面而不是發送郵件界面。你有一個很好的理想嗎?謝謝 – user2297463 2013-04-25 05:29:48

+0

@ user2297463你想檢查設備是否有郵件應用程序或設備可以發送郵件。請清楚,我想我可以幫助你。 – satheeshwaran 2013-04-25 05:59:09

+0

看我的編輯,你可以使用最後兩條語句打開你的郵件應用程序。 – satheeshwaran 2013-04-25 06:04:36

0

您無法打開郵件應用程序。您可以使用MFMailComposeViewControllermailto: URL打開撰寫電子郵件界面。

相關問題