在项目中经常需要使用到扫描二维码后根据是否安装app进行不同的操作.有的是跳转到指定的页面,有的是需要去下载app的页面.如何进行目的性跳转:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
if ([[url absoluteString] rangeOfString:@"ycxdrive"].location == 0) {
NSRange range = [string rangeOfString:@"type"];
string = [string substringFromIndex:range.location];
NSArray *array = [string componentsSeparatedByString:@"&"];
NSMutableDictionary *APPInfoDicAboutFriend = [NSMutableDictionary dictionary];
[array enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj containsString:@"type"]) {
NSRange typeRange = [obj rangeOfString:@"="];
NSString *typeString = [obj substringFromIndex:typeRange.location+1];
[APPInfoDicAboutFriend setObject:typeString forKey:@"type"];
}else if ([obj containsString:@"userId"]){
NSRange userIDRange = [obj rangeOfString:@"="];
NSString *userIDString = [obj substringFromIndex:userIDRange.location+1];
[APPInfoDicAboutFriend setObject:userIDString forKey:@"userId"];
}
}];
YCXRootTabBarController *rootTabVC = (YCXRootTabBarController *)self.window.rootViewController;
rootTabVC.selectedIndex = 3;
[rootTabVC.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
YCXBaseNavigationController *baseVC = obj;
if ([baseVC.viewControllers[0] isKindOfClass:[YCXProfileController class]]) {
YCXProfileController *profileVC = baseVC.viewControllers[0];
PersonalProfileController *vc = [[PersonalProfileController alloc] initWithNibName:@"PersonalProfileController" bundle:nil];
[profileVC.navigationController pushViewController:vc animated:YES];
}
}];
}
}
return YES;
}