Launching Other Apps within an iPhone Application

转载 2011年01月22日 15:36:00
Posted on October 16, 2008 by Rodney Aiglstorfer in Cocoa

 

In an earlier post I talked about how to launch the browser from within an iPhone application using the UIApplication: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:

http://maps.google.com/maps?q=${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:

1
2
3
4
5
6
7
8
9
10
11
// 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: @ "http://maps.google.com/maps?q=%@" , 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:

1
[
[
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.

1
[
[
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:

http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8

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:

1
2
NSURL
 *
appStoreUrl =
 [
NSURL
 URLWithString:
@
"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"
]
;
[ [ UIApplication sharedApplication] openURL: appStoreUrl] ;
Share with other iOS Developers:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

http://iphonedevelopertips.com/cocoa/launching-the-browser-from-within-an-iphone-application.html

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

It depends on the app you wish to launch. Some of them register URLs that let you launch links like itunes:// and the like. Check this out: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StandardBehaviors/StandardBehaviors.html#//apple_ref/doc/uid/TP40007072-CH4-SW7

The important section is the one entitled "Implementing Custom URL Schemes".

EDIT: Here's a link to a website that catalogs the various URLs for existing apps: http://handleopenurl.com/ .

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

http://stackoverflow.com/questions/3443346/can-an-ipad-app-directly-launch-another-app

Sending Content to Other Apps 将内容发送到其他应用程序

When you construct an intent, you must specify the action you want the intent to "trigger." Android ...
  • sergeycao
  • sergeycao
  • 2013年04月27日 09:43
  • 959

iOS APP最新上架流程资料收集和遇到坑时的解决方案

2016年最新的上架流程资料收集,和遇到坑的解决方法
  • qq_31389903
  • qq_31389903
  • 2016年05月12日 10:32
  • 901

Oracle函数 --聚合函数中的语法within group

Oracle的聚合函数一般与group by 联合使用,但一般通过group by 聚合 但某些聚合函数会后跟 WITHIN GROUP (ORDER BY expr [ DESC ...
  • richieruan
  • richieruan
  • 2017年01月10日 16:08
  • 3457

开发遇到的问题

cannot create __weak reference in file using manual reference counting 解决1: 设置项目中的build setting ->...
  • KLong27
  • KLong27
  • 2017年05月08日 17:00
  • 436

jenkins master升级后无法启动slave

惊心动魄一刻,master升级到最新war包,冲启动后,10多台slave无法启动。一下在大数据部的分布式计算都无法运行。紧急恢复到过去版本的war包,仍然不行,下载了最新版本的war包,重启后依然不...
  • sheismylife
  • sheismylife
  • 2014年11月14日 15:04
  • 3468

基于MFC的ActiveX控件的退出(卸载)

一直以来,写了控件后用起来很正常,最近,客户要把这控件用在web页面上,那么问题它就来了。大多数时候的运行环境: os: win7、win10 浏览器:ie8、ie11,这里不考虑ie之外的其它浏...
  • jszj
  • jszj
  • 2017年01月12日 17:58
  • 926

Receiving Content from Other Apps 接收来自其他应用程序的内容

Just as your application can send data to other applications, so too can it easily receive data from...
  • sergeycao
  • sergeycao
  • 2013年04月27日 09:46
  • 804

【转帖】Android zxing 横屏 改竖屏识别解决方案

在网上找了很多方法,但最后都有问题,自己调试了好几个小时,最后终于完美解决了竖屏识别。 首先你需要有zxing项目的简化版代码,在这里。 使用简化版可以免去许多不必要的代码,方便学习研究,...
  • ilittleone
  • ilittleone
  • 2013年10月15日 11:28
  • 15920

关于Other Link Flag的有关说明

背景 在ios开发过程中,有时候会用到第三方的静态库(.a文件),然后导入后发现编译正常但运行时会出现selector not recognized的错误,从而导致app闪退。接着仔细阅...
  • cjh965063777
  • cjh965063777
  • 2016年07月11日 15:12
  • 1177

【Android学习】File文件

1,ActivityManager1)概念与系统中正在运行的所有活动进行交互。2)实现①获取ActivityManager对象在拥有context的环境下: ActivityManager activ...
  • SunshineTan
  • SunshineTan
  • 2017年12月13日 13:31
  • 89
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Launching Other Apps within an iPhone Application
举报原因:
原因补充:

(最多只允许输入30个字)