open other app from my app

1. 在需要被启动的app中的plist文件, 右击Information Property List, 选择Add Row


 

2. 选择"URL types"作为键值


3. 展开的"Item1",为URL identifier提供一个值,这个值可以是任意的, 但是惯例是使用"反向域名(reverse domain name)"(例如:com.mycompany.myapp).


 

4. 右击"Item1", 选择"Add row"

 


 

5. 选择"URL Schemes"作为键值

 


 

6. 为这个"URL Schemes"输入对应的值(例如: "myapp://"那么就输入"myapp"). 这里可以输入多个不同的值.


7. 这是在另一个程序, 启动代码:

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

 

 

-----------------------

Optionally Handle the URL

Now that the URL has been registered. Anyone can start the application by opening a URL using your scheme.

Here are a few examples …

myapp://
 
myapp://some/path/here
 
myapp://?foo=1&bar=2
 
myapp://some/path/here?foo=1&bar=2

The iPhone SDK, when launching the application in response to any of the URLs above, will send a message to the UIApplicationDelegate.

If you want to provide a custom handler, simply provide an implementation for the message in your delegate. For example:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
{
  // Do something with the url here
}

A common technique is to parse the URL passed in and pull from it the parameters that will be used by various views in the application and store them in the User Preference. Below is an example where we store the URL as a value parameter “url” in just such a manner …

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if (!url) {  return NO; }
 
    NSString *URLString = [url absoluteString];
    [[NSUserDefaults standardUserDefaults] setObject:URLString forKey:@"url"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}

Now you have everything you need to enable others to wake-up your application and even pass it information! Enjoy!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值