天天看點

IOS 開發:調用打電話,發短信,打開網址

1、調用 自帶mail

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]];

2、調用 電話phone

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];

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

調用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”)  

}

發送郵件的為:

導入#import <MessageUI/MFMailComposeViewController.h>

實作代理:MFMailComposeViewControllerDelegate

//發送郵件

-(void)sendMail:(NSString *)subject content:(NSString *)content{

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

    if([MFMailComposeViewController canSendMail])

    {

        [controller setSubject:subject];

        [controller setMessageBody:content isHTML:NO];

        controller.mailComposeDelegate = self;

        [self presentModalViewController:controller animated:YES];

    }    

}

//郵件完成處理

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{

    [self dismissModalViewControllerAnimated:YES];

    if (result == MessageComposeResultCancelled)

        NSLog(@”Message cancelled”);

    else if (result == MessageComposeResultSent)

        NSLog(@”Message sent”); 

    else 

        NSLog(@”Message failed”);  

}