iOS笔记UI--app间跳转

我们通过系统的openURL方法,可以从当前的app跳转到其他任意app去,包括系统自带的、以及我们开发的app。

本文模拟A app跳转到 B app

// A app
//  ViewController.m
//  程序跳转
//
//  Created by hhg on 15/10/23.
//  Copyright (c) 2015年 hhg. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // 为我们的程序设置一个唯一的标识,那么其他软件就可以使用openURL方法通过唯一标识来打开我们的程序
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"zapp:"]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
//  B app
//  AppDelegate.m
//  MyApp
//
//  Created by hhg on 15/10/23.
//  Copyright (c) 2015年 hhg. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return YES;
}

// 当其他程序通过openURL打开该程序的时候,会触发这个方法
// URL ,就是其他程序打开时候的URL
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"跳转成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alertView show];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

- (void)applicationWillTerminate:(UIApplication *)application {
}
@end

B app 在info.plist 文件里面需要设置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string></string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>zapp</string>
        </array>
    </dict>
</array>
</plist>

如图:
url设置

猜你喜欢

转载自blog.csdn.net/csdn_hhg/article/details/80446105