如何代码实现跳转safari,phone或message?

在相应的代码中写入:

1、调用 电话phone
 [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:@"tel://4008008288"]];

2、调用自带 浏览器 safari
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:@"http://www.abt.com"]];

3、调用 自带mail
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:@"mailto://[email protected]"]];

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

5,跳转到系统设置相关界面

[[UIApplication
sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];

其中,发短信,发Email的功能只能填写要发送的地址或号码,无法初始化发送内容,如果想实现内容的话,还需要更复杂一些,实现其各自的委托方法。

若需要传递内容可以做如下操作:
加入: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")

elseif (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");

elseif (result == MessageComposeResultSent)

NSLog(@"Message sent");

else       NSLog(@"Message failed");

}

默认发送短信的界面为英文的,解决办法为:在.xib 中的Localization添加一組chinese

时间: 2024-08-29 09:46:16

如何代码实现跳转safari,phone或message?的相关文章

PHP JS HTML ASP页面跳转代码 延时跳转代码

1.PHP延时跳转代码 //跳转到浏览界面 header("Refresh:1;url=machine_list.php"); //不延时 <?php header("location: http://www.baidu.com"); ?> 2.JavaScript 跳转 <script language="javascript"> window.location= "http://www.baidu.com&q

A标签执行js 代码和跳转

5.执行JS代码: ????<a href="javascript:js代码">内容</a> ⑥.使用js来实现空链接 写法:<a href="javascript:void(0)"></a> ⑦.锚点 ????需要两个a链接搭配使用,第一个a链接设置锚点名,第二个a链接实现跳转功能. <a name="设置锚点的名称"></a> 用法1:同一页内实现跳转 示例: 设置锚点名

PHP JS HTML ASP页面跳转代码 延时跳转代码 返回到上一界面并刷新

1.PHP延时跳转代码 //跳转到浏览界面 header("Refresh:1;url=machine_list.php"); //不延时 <?php header("location: http://www.baidu.com"); ?> //PHP内JS输出代码 echo ("<script language=\"JavaScript\">alert(\"修改成功!\");location

php 代码设置跳转

/* header 跳转:更改页面头部信息,地址跳转,尽量用绝对地址, js跳转:在php中输出js的跳转语句 */ //1,后台的php跳转 header('location:'.BASE_URL.'index.php?m=news&c=index&admin=1'); //更改网页头部信息,地址跳转,绝对地址:把路径写全 //header('loaation:index.php'); //相对地址,相对于当前位置的地址,不推荐使用相对地址 //2,js跳转 echo '<scri

java直接生成zip压缩文件精简代码(跳过txt文件)

/** * @param args */ public static void main(String[] args) throws Exception{ ZipOutputStream zos = null; zos = new ZipOutputStream(new FileOutputStream("c:\\temp7.zip")); String ss = "cName\t\tcCode\t\tcreateDate\n"; ss += "dbc券9

Mvc分页扩展类 分页代码 带跳转

public static class HtmlPager { public static MvcHtmlString MvcPager(this HtmlHelper html, string currentPageStr, int pageSize, int totalCount) { var queryString = html.ViewContext.HttpContext.Request.QueryString; int currentPage = 1; //当前页 var total

android入门,activity跳转,并传递message

首先是布局文件,如下: activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="

大神总结的

1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用) 其实在代码里还是可以设置的,那就是删除背景view [[self.searchBar.subviews objectAtIndex:0] removeFromSuperview]; 2,NSDate使用 [java] view plaincopy 字母  日期或时间元素    表示     示例 G     Era   标志符     Text     

js网址跳转实例代码

js网址跳转实例代码:网址跳转是常用的功能,比如点击一个按钮实现跳转,或者说希望一条新闻打开后可以跳转到其他页面,就可以直接在编辑器中输入跳转代码.下面就简单列举一下js跳转代码,可以根据实际情况选择使用.方式一: window.location.href="http://www.softwhy.com"; 以上代码可以跳转到指定的链接.方式二: window.history.back(-1); 以上代码可以返回之前访问的页面.方式三: self.location="http