业精于勤,荒于嬉
全部博文(763)
分类: C/C++
2010-03-03 15:23:06
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
参考资料: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:
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:
|
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 :
|
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:
|
NOTE When providing an international number you will need to include the country code.
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.
|
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.
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:
|