[[uiapplication sharedapplication] openurl:[nsurl urlwithstring:[nsstring stringwithformat:@"tel://%@",_phonenumber]]];
調用系統的發送短信的界面,需要引入以下頭檔案:
#import <messageui/messageui.h>
系統短信界面的調用很簡單,隻需下面幾句代碼:
<a href="http://my.oschina.net/u/2340880/blog/408115#">?</a>
1
2
3
4
5
<code> </code><code>mfmessagecomposeviewcontroller * con = [[mfmessagecomposeviewcontroller alloc]init];</code>
<code> </code><code>if</code> <code>([mfmessagecomposeviewcontroller cansendtext]) {</code>
<code> </code><code>con.recipients=@[_phonenumber];</code><code>//電話數組</code>
<code> </code><code>con.messagecomposedelegate=self;</code>
<code> </code><code>[self presentviewcontroller:con animated:yes completion:nil];</code>
下面将messageui的一些常用方法總結如下:
+ (bool)cansendtext
判斷是否支援發送文字
+ (bool)cansendsubject;
判斷是否支援發送主題資訊
+ (bool)cansendattachments;
判斷是否支援發送附件
+ (bool)issupportedattachmentuti:(nsstring *)uti;
判斷是否支援統一标示附件
- (void)disableuserattachments;
禁止發送附件
@property(nonatomic,copy) nsarray *recipients;
聯系人數組,會顯示在發送人清單裡
@property(nonatomic,copy) nsstring *body;
資訊主體内容
@property(nonatomic,copy) nsstring *subject;
資訊标題
@property(nonatomic,copy, readonly) nsarray *attachments;
資訊附件數組 隻讀的 裡面是字典
- (bool)addattachmenturl:(nsurl *)attachmenturl withalternatefilename:(nsstring *)alternatefilename;
根據url路徑和添加附件,傳回yes表示添加成功
- (bool)addattachmentdata:(nsdata *)attachmentdata typeidentifier:(nsstring *)uti filename:(nsstring *)filename;
根據data資料添加附件
- (void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result;
mfmessagecomposeviewcontrollerdelegate的代理方法,result會傳回來一個結果,枚舉如下:
6
7
8
<code>enum</code> <code>messagecomposeresult {</code>
<code> </code><code>//取消發送</code>
<code> </code><code>messagecomposeresultcancelled,</code>
<code> </code><code>//發送成功</code>
<code> </code><code>messagecomposeresultsent,</code>
<code> </code><code>//發送失敗</code>
<code> </code><code>messagecomposeresultfailed</code>
<code>};</code>