第一步:
//在要跳转页面的触发跳转方法中写入跳转路径
//格式:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"要跳转到的应用名称://"]];
//点击跳转到应用
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"Second://"]];
//创建路径
NSString *urlString = [NSStrings tringWithFormat:@"Second://appid=%d&appName=应用名称",arc4random()];
//编码(存在中文需要编码)
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//添加路径
NSURL*url = [NSURL URLWithString:urlString];
//创建APP
UIApplication *app = [UIApplication sharedApplication];
//拉入白名单
if([app canOpenURL:url]) {
[app openURL:url];
}
//在info.plist中配置LSApplicationQueriesSchemes type:array
//在下一级的value中填写Second(要跳转到的APP名称)
设置第二步:
//在要跳转到的APP中设置自己的URL路径
//identifier可随意写
//URL Schemes要写入该APP的名称
设置//在该应用的AppDelegate中.导入接收值的控制器,对其实例变量,进行操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
//把上个应用跳转过来的一些信息显示到lable上
_rootViewController = (ViewController *)self.window.rootViewController;
return YES;
}
//接收值的方法
- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary *)options {
//Second://appid=%d&appName=应用名称会接收到全部字符串不好处理
//NSString *urlString = url.absoluteString;
//appid=%d&appName=应用名称
NSString *para = url.host;
//对接收到的字符串进行拆分
NSArray *array = [para componentsSeparatedByString:@"&"];
//再拆分并接收
NSString *appID = [[[array firstObject] componentsSeparatedByString:@"="] lastObject];
//再拆分并接收
NSString *appName = [[[array lastObject] componentsSeparatedByString:@"="] lastObject];
//接收并显示
_rootViewController.messageLabel.text= [NSString stringWithFormat:@"appID:%@ \nappName:%@",appID,appName];
return YES;
}
网友评论