在<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>