IOS自帶Email的兩種方法
1.openURL
使用openURL呼叫系統郵箱客戶端是我們在IOS3.0以下實現發郵件功能的主要手段。我們可以通過設定url裡的相關引數來指定郵件的內容,不過其缺點很明顯,這樣的過程會導致程式暫時退出。下面是使用openURL來發郵件的一個小例子:- #pragma mark - 使用系統郵件客戶端傳送郵件
- -(void)launchMailApp
- {
- NSMutableString *mailUrl = [[[NSMutableString alloc]init]autorelease];
- //新增收件人
-
NSArray *toRecipients = [NSArray arrayWithObject: @
- [mailUrl appendFormat:@"mailto:%@", [toRecipients componentsJoinedByString:@","]];
- //新增抄送
- NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
-
[mailUrl appendFormat:@"?cc=%@", [ccRecipients componentsJoinedByString:@
- //新增密送
- NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
- [mailUrl appendFormat:@"&bcc=%@", [bccRecipients componentsJoinedByString:@","]];
- //新增主題
- [mailUrl appendString:@"&subject=my email"];
- //新增郵件內容
-
[mailUrl appendString:@
- NSString* email = [mailUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- [[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
- }
2.MFMailComposeViewController
MFMailComposeViewController是在IOS3.0新增的一個介面,它在MessageUI.framework中。通過呼叫MFMailComposeViewController,可以把郵件傳送視窗整合到我們的應用裡,傳送郵件就不需要退出程式了。MFMailComposeViewController的使用方法:- 1.專案中引入MessageUI.framework;
- 2.在使用的檔案中匯入MFMailComposeViewController.h標頭檔案;
- 3.實現MFMailComposeViewControllerDelegate,處理郵件傳送事件;
- 4.調出郵件傳送視窗前先使用MFMailComposeViewController裡的“+ (BOOL)canSendMail”方法檢查使用者是否設定了郵件賬戶;
- 5.初始化MFMailComposeViewController,構造郵件體
- //
- // ViewController.h
- // MailDemo
- //
- // Created by LUOYL on 12-4-4.
- // Copyright (c) 2012年 http://luoyl.info. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import <MessageUI/MFMailComposeViewController.h>
- @interface ViewController : UIViewController<MFMailComposeViewControllerDelegate>
- @end
- #pragma mark - 在應用內傳送郵件
- //啟用郵件功能
- - (void)sendMailInApp
- {
- Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
- if (!mailClass) {
- [self alertWithMessage:@"當前系統版本不支援應用內傳送郵件功能,您可以使用mailto方法代替"];
- return;
- }
- if (![mailClass canSendMail]) {
- [self alertWithMessage:@"使用者沒有設定郵件賬戶"];
- return;
- }
- [self displayMailPicker];
- }
- //調出郵件傳送視窗
- - (void)displayMailPicker
- {
- MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
- mailPicker.mailComposeDelegate = self;
- //設定主題
- [mailPicker setSubject: @"eMail主題"];
- //新增收件人
- NSArray *toRecipients = [NSArray arrayWithObject: @"[email protected]"];
- [mailPicker setToRecipients: toRecipients];
- //新增抄送
- NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
- [mailPicker setCcRecipients:ccRecipients];
- //新增密送
- NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
- [mailPicker setBccRecipients:bccRecipients];
- // 新增一張圖片
- UIImage *addPic = [UIImage imageNamed: @"[email protected]"];
- NSData *imageData = UIImagePNGRepresentation(addPic); // png
- //關於mimeType:http://www.iana.org/assignments/media-types/index.html
- [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"];
- //新增一個pdf附件
- NSString *file = [self fullBundlePathFromRelativePath:@"高質量C++程式設計指南.pdf"];
- NSData *pdf = [NSData dataWithContentsOfFile:file];
- [mailPicker addAttachmentData: pdf mimeType: @"" fileName: @"高質量C++程式設計指南.pdf"];
- NSString *emailBody = @"<font color='red'>eMail</font> 正文";
- [mailPicker setMessageBody:emailBody isHTML:YES];
- [self presentModalViewController: mailPicker animated:YES];
- [mailPicker release];
- }
- #pragma mark - 實現 MFMailComposeViewControllerDelegate
- - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
- {
- //關閉郵件傳送視窗
- [self dismissModalViewControllerAnimated:YES];
- NSString *msg;
- switch (result) {
- case MFMailComposeResultCancelled:
- msg = @"使用者取消編輯郵件";
- break;
- case MFMailComposeResultSaved:
- msg = @"使用者成功儲存郵件";
- break;
- case MFMailComposeResultSent:
- msg = @"使用者點擊發送,將郵件放到佇列中,還沒傳送";
- break;
- case MFMailComposeResultFailed:
- msg = @"使用者試圖儲存或者傳送郵件失敗";
- break;
- default:
- msg = @"";
- break;
- }
- [self alertWithMessage:msg];
- }
相關推薦
IOS自帶Email的兩種方法
IOS系統框架提供的兩種傳送Email的方法:openURL 和 MFMailComposeViewController。藉助這兩個方法,我們可以輕鬆的在應用里加入如使用者反饋這類需要傳送郵件的功能。 1.openURL 使用openURL呼叫系統郵箱客戶端是我們在
Ubuntu開機自啟動的兩種方法總結
一.第一種方法 1,新建個指令碼檔案new_service.sh #!/bin/bash # command content exit 0 2,設定許可權 sudo chmod 755 new_service.sh 3,把指令碼放置到啟動目錄下 sudo mv new_servi
SA:T1編寫主函數法和T2Matlab自帶的SA工具箱GUI法,兩種方法實現對二元函數優化求解——Jason niu
lin plot itl 最優解 IT 主函數 alt 圖片 gui %SA:T1法利用Matlab編寫主函數實現對定義域[-5,5]上的二元函數求最優解—Jason niu [x,y] = meshgrid(-5:0.1:5,-5:0.1:5); z = x.^2 +
android中RadioButton中的自帶的圓圈如何去掉,兩種方法,一種.xml、一種程式碼中
第一種.xml中 我想大家都知道 android:button="@null"其實這就是簡單的多RadioButton做的一個自定義,null就是給他為空,所以就變相的隱藏掉了它自帶那個圓圈。 重點是第二種的方法,在java程式碼中:RadioButton IB_PullD
深入講解iOS鍵盤三:自定義鍵盤的兩種方法
iOS系統提供了多種鍵盤,我們可以通過Enum型別設定。但有的時候由於某些特殊業務的需要,我們不得不自定義鍵盤,比如某些銀行的APP處於安全考慮,他們鍵盤數字的位置是隨機的,這個時候只能自定義鍵盤。幸運的是,iOS也為我們提供了多種方式自定義鍵盤。我們可以根據自身情況選擇合適
使用PHP生成二維碼的兩種方法(帶logo圖像)
好的 區域 chl sta n) 方便 ram 尺寸 混合 一、利用Google API生成二維碼 Google提供了較為完善的二維碼生成接口,調用API接口很簡單,以下是調用代碼: $urlToEncode="http://www.jb51.net"; generat
輸入帶空格字符串的兩種方法
現在 a10 lin ould char 錯誤 會有 遇到 意思 這是我們平常用的: char s[100]; scanf("%s",s);//cin>>s; 輸入字符串時,當遇到空格就自動停止輸入,導致空格後門的字符沒有按我們設想的輸入。
MyBatis無限級分類實現的兩種方法--自關聯與map集合
except app exce utf-8 elf findall ldr ati tex 1、這回先創建數據庫吧 下表cid是CategoryId的縮寫,cname是CategoryName的縮寫,pid是parentId的縮寫 無限級分類一般都包含這三個屬性,至少也要包
學習windows編程 day3 之 自定義畫筆的兩種方法
cas delete tro HP rec col 編程 UC eat LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; P
PHP生成帶logo圖像二維碼的兩種方法
width 調用 height word api 生成 table 中間 log 本文主要和大家分享PHP生成帶logo圖像二維碼的兩種方法,主要以文字和代碼的形式和大家分享,希望能幫助到大家。 一、利用Google API生成二維碼Google提供了較為完善的二維碼生
Email 的兩種方法
IOS系統框架提供的兩種傳送Email的方法:openURL 和 MFMailComposeViewController。藉助這兩個方法,我們可以輕鬆的在應用里加入如使用者反饋這類需要傳送郵件的功能。 1.openURL 使用openURL呼叫系統郵
CSS實現自適應不同大小螢幕的背景大圖的兩種方法(轉自簡書)
CSS實現自適應不同大小螢幕的背景大圖的兩種方法 一張清晰漂亮的背景圖片能給網頁加分不少,設計師也經常會給頁面的背景使用大圖,我們既不想圖片因為不同解析度圖片變形,也不希望當在大屏的情況下,背景有一塊露白,簡而言之,就是實現能自適應螢幕大小又不會變形的背景大圖,而且背景圖片不會隨著
在TensorFlow中自定義梯度的兩種方法
前言 在深度學習中,有時候我們需要對某些節點的梯度進行一些定製,特別是該節點操作不可導(比如階梯除法如 10 /
echart去除網格線的兩種方法和echart圖自適應
1. yAxis : [ { &nb
ionic2 從子頁面返回帶引數的兩種方法
1、使用 Modal 代替 NavController 的 push 方法,然後在子頁面通過 dismiss 方法關閉時可攜帶引數返回母頁面。 在母頁面中: getDetailNews(id) { let newsModal = this.modalCtrl.cr
css實現兩欄佈局,左側固定寬,右側自適應的七種方法
一個面試會問的問題,如何實現兩個盒子,左側固定寬度,右側自適應。 下面是實現的其中方法: 1、利用 calc 計算寬度的方法 css程式碼如下: .box{overflow: hidden;height: 100px;margin: 10px 0;} .box&
docker容器自定義映象的兩種方法
目錄 1.使用docker commit 使用映象啟動容器,在該容器上修改,在使用命令另存為一個映象 實現思路:使用一個基礎的映象,這個映象可以在centos的官網進行下載,在使用docker進行建立 一個容器,進入到該容器中,刪除原有的yum
iOS兩種方法刪除NSUserDefaults所有記錄
//方法一 NSString *appDomain = [[NSBundlemainBundle] bundleIdentifier];[[NSUserDefaults standardUser
自定義具有跑馬燈效果的兩種方法
普通的TextView可以實現跑馬燈,但是隻有當焦點在它上面時才有效。如何做一個自動的跑馬燈呢?第一種:繼承TextView,然後重寫isFocused()方法就可以了,簡單!Java程式碼 import android.content.Context; import
robotframework使用python自定義“關鍵字”的兩種方法:匯入庫(LIB)和匯入模組(py檔案)
1、匯入庫,需要把檔案做成包的形式 常見放置在,python主目錄的 \Lib\site-packages下 __init__.py 好處是:適合大規模的開發,包有多人負責,分模組開發,無限擴充套件檔案數量 缺點是:統一歸檔相對麻煩 2、匯入檔案,直