iOS 調用短信、電話、郵件、瀏覽器等

iOS 調用短信、電話、郵件、瀏覽器等


1、調用 自帶mail
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

2、調用 電話phone

 

3、調用 SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];

4、調用自帶 瀏覽器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];

調用phone可以傳遞號碼,調用SMS 只能設定號碼,不能初始化SMS內容。

若需要傳遞內容可以做如下操作:
加入:MessageUI.framework

#import <MessageUI/MFMessageComposeViewController.h>

實現代理:MFMessageComposeViewControllerDelegate

 

複製代碼
-(IBAction)dialClicked:(id)sender
{
    NSString *phoneNum = uil_phoneNumber.text;// 電話號碼
    
    //第一種方法  直接撥打電話,不提示用戶,但是通話結束後會返回系統自帶的通訊錄列表
    
    if (phoneNum != nil && ![phoneNum isEqualToString:@""]) {
        NSString *telUrl = [NSString stringWithFormat:@"tel://%@",phoneNum];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
     
    
    // 第二種方法  在打電話前先提示用戶,通話結束後反饋開發者的應用程序     不合法,可能無法通過蘋果商店的審覈。
    
  
     if (phoneNum != nil && ![phoneNum isEqualToString:@""]) {
     NSString *telUrl = [NSString stringWithFormat:@"telprompt:%@",phoneNum];
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
     
     
    // 第三種方法(效果和方法二一樣) 打電話前提示用戶,能返回開發者的應用程序
    
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];      
    if ( !phoneCallWebView && ![phoneNum isEqualToString:@""]) {          
        phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];// 這個webView只是一個後臺的容易 不需要add到頁面上來  效果跟方法二一樣 但是這個方法是合法的
    } 
    [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];
    [self.view addSubview:phoneCallWebView];
     
}
複製代碼

 

調用sendSMS函數
//內容,收件人列表
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];

if([MFMessageComposeViewController canSendText])

{

controller.body = bodyOfMessage;

controller.recipients = recipients;

controller.messageComposeDelegate = self;

[self presentModalViewController:controller animated:YES];

}

}

// 處理髮送完的響應結果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];

if (result == MessageComposeResultCancelled)
NSLog(@"Message cancelled")
else if (result == MessageComposeResultSent)
NSLog(@"Message sent") 
else 
NSLog(@"Message failed") 
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章