iOS 应用程序间跳转

在<strong><span style="font-size:18px;">目标程序</span></strong>的plist文件里面修改:

打开xxxx-info.plist,添加一项URL types

打开URL types,将item0的URL identifier修改为URL Schems

展开URL Schemes,将item0的内容修改为xxxApp(此为跳转的key:例如key2)<pre name="code" class="objc">在源程序里面需要跳转的地方,添加代码

NSURL *myUrl = [NSURL URLWithString:@"xxxApp://abcde"]; //xxxApp为<strong><span style="font-size:18px;">目标</span></strong>App跳转的key, 例如:key2

  if([[UIApplication sharedApplication] canOpenURL:myUrl]){

      [[UIAppliactioin sharedApplication] openURL:myUrl];

  }
若想要获取源程序传递过来的参数, 则需要在源程序中得<span style="font-family: Arial, Helvetica, sans-serif;">plist文件里面做同样地修改, 只是将item0的内容修改为本app的key, 例如key1</span>
然后在<span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;">目标程序的appDelegate中实现</span><pre name="code" class="objc">- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
 
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p1"><span class="s1">if</span><span class="s2"> ([[url </span><span class="s3">scheme</span><span class="s2">] </span><span class="s3">isEqualToString</span><span class="s2">:</span>@"key2"<span class="s2">]) {</span></p>
 
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p2">        <span class="s3">NSLog</span>(<span class="s4">@"</span><span class="s5">从</span><span class="s4">%@</span><span class="s5">跳转过来的</span><span class="s4"> - %@"</span>,sourceApplication,[url <span class="s3">resourceSpecifier</span>]);</p>
 
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p3"><span class="s2">        </span><span class="s1">self</span><span class="s2">.</span><span class="s6">otherString</span><span class="s2"> = [[[url </span>resourceSpecifier<span class="s2">] </span>componentsSeparatedByString<span class="s2">:</span><span class="s4">@"//"</span><span class="s2">] </span>objectAtIndex<span class="s2">:</span><span class="s7">1</span><span class="s2">];</span></p>
 
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p2">        <span class="s3">NSLog</span>(<span class="s4">@"</span><span class="s5">传递过来的参数</span><span class="s4"> = %@"</span>,<span class="s1">self</span>.otherString);      </p>
 
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p2">    }</p>
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p8"><span class="s2"> </span>return<span class="s2"> </span>YES<span class="s2">;</span></p>
 
<pre name="code" class="objc"><span style="font-size: 18px; font-weight: bold; font-family: Arial, Helvetica, sans-serif;"></span><p class="p2">}</p>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值