Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5542955
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: C/C++

2010-03-03 15:23:06

iPhone的单任务模式为手机节省了资源,保障了程序的安全运行,但是这一做法也遭到很多人的反对,为很多应用带来了不便。如今,openURL这个方法为解决这一问题带来了希望,虽然离多任务模式还有差距,但毕竟给了大家一个实现更强大应用的可行方法。

openURL的使用方法:

CODE:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appString]];其中系统的appString有:

CODE:

Map   
Email  mailto://myname@google.com
Tel    tel://10086
Msg    sms://10086
除此之外,还可以自己定义URL,方法如下:

CODE:

打开info.plist,添加一项URL types
展开URL types,再展开Item1,将Item1下的URL identifier修改为URL Scheme
展开URL Scheme,将Item1的内容修改为myapp
其他程序可通过myapp://访问此自定义URL
参考资料:
1. http://iphonedevelopertips.com/c ... ne-application.html
2. http://iphonedevelopertips.com/c ... tom-url-scheme.html
 
 
 
 
 
openURL能帮助你运行Maps,SMS,Browser,Phone甚至其他的应用程序。这是Iphone开发中我经常需要用到的一段代码,它仅仅只有一行而已。
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
这个程序通过基础的协议支持拨打电话的功能
译者附:
    -(IBAction)openMaps {//打开地图
    // Where is Apple on the map anyway?
    NSString* addressText = @”1 Infinite Loop, Cupertino, CA 95014″;
    // URL encode the spaces
    addressText =  [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
    NSString* urlText = [NSString stringWithFormat:@"@", addressText];
    // lets throw this text on the log so we can view the url in the event we have an issue
    NSLog(urlText);
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
    }
    -(IBAction)openEmail {//打开mail
    // Fire off an email to apple support
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
    }
    -(IBAction)openPhone {//拨打电话
    // Call Google 411
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
    }
    -(IBAction)openSms {//打开短信
    // Text to Google SMS
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
    }
    -(IBAction)openBrowser {//打开浏览器
    // Lanuch any iPhone developers fav site
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];
    }
 
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wwwcybcom/archive/2009/09/17/4563787.aspx
 
 

 

In an earlier post I talked about how to launch the browser from within an iPhone application using the UIApplciation:openURL: method.

It is also possible to use this same technique to launch other applications on the iPhone that are very useful.

Examples of some of the key applications that you can launch via URL are:

  • Launch the Browser (see earlier post )
  • Launch Google Maps
  • Launch Apple Mail
  • Dial a Phone Number
  • Launch the SMS Application
  • Launch the Browser
  • Launch the AppStore

Launch Google Maps

The URL string for launching Google Maps with a particular keyword follows this structure:

${QUERY_STRING}

The only trick to this is to ensure that the value for the ${QUERY_STRING} is properly URL encoded. Here is a quick example of how you would launch Google Maps for a specific address:

 

// Create your query ...

NSString* searchQuery = @"1 Infinite Loop, Cupertino, CA 95014";
 
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly

searchQuery = [addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
 
// Now create the URL string ...

NSString* urlString = [NSString stringWithFormat:@"%@", searchQuery];
 
// An the final magic ... openURL!

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];


 

Launch Apple Mail

Also very useful, is the ability to enable a user to quickly send an email by launching the email client in compose mode and the address already filled out. The format of this URI should be familiar to anyone that has done any work with HTML and looks like this:

mailto://${EMAIL_ADDRESS}

For example, here we are opening the email application and filling the “to:” address with info@iphonedevelopertips.com :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@mailto://info@iphonedevelopertips.com]]

 

Dial a Phone Number (iPhone Only)

You can use openURL: to dial a phone number. One advantage this has over other URLs that launch applications, is that the dialer will return control back to the application when the user hits the “End Call” button.

Anyone familiar with J2ME or WML will find this URL scheme familiar:

tel://${PHONE_NUMBER}

Here is an example of how we would dial the number (800) 867-5309:

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

NOTE When providing an international number you will need to include the country code.

Launch the SMS Application

Also not supported by the iPod Touch, is the ability to quickly setup the SMS client so that your users can quickly send a text message. It is also possible to provide the body of the text message.

The format looks like this:

sms:${PHONENUMBER_OR_SHORTCODE}

NOTE: Unlike other URLs, an SMS url doesn’t use the “//” syntax. If you add these it will assume it is part of the phone number which is not.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:55555"]];

 

NOTE: According to the official SMS specification, you should be able to send a body as well as the phone number by including “?body=” parameter on the end of the URL … unfortunately Apple doesn’t seem to support this standard.

Launching the AppStore

Finally, it is worth noting that you can launch the AppStore and have the "buy" page of a specific application appear. To do this, there is no special URL scheme. All you need to do is open up iTunes to the application you want to launch; right-click on the application icon at the top left of the page; and select Copy iTunes Store URL .

The URL will look something like this:

Launching the AppStore URL is exactly the same as you would launch the browser. Using the link above, here is an example of how we would launch the AppStore:


 

NSURL *appStoreUrl = [NSURL URLWithString:@""];
[[UIApplication sharedApplication] openURL:appStoreUrl];


阅读(5178) | 评论(0) | 转发(1) |
0

上一篇:BMP图像文件格式(4)

下一篇:游戏AI基础

给主人留下些什么吧!~~