iOS 网页进入APP

前言

使用scheme跳转,URL参数分离,跳转路由

scheme

转送门
https://www.jianshu.com/p/138b44833cda
https://www.jianshu.com/p/0811ccd6a65d

safari

safari地址MouoApp://shopDetal?userId=10965

使用

AppDelegate

// iOS 9 以上请用这个
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{
 if([url.scheme isEqualToString:@"mouoapp"]){
            //url.query
            //进入的时候判断逻辑为
            if (self.mainController && [MouoUserManager sharedAccountManager].user) {
                [JumpManager gotoControllerWithScheme:url.absoluteString controller:self.mainController.currentSelectController];
            }
            return YES;
        }
}

路由类

+ (MouoBaseController *)gotoControllerWithScheme:(NSString *)scheme controller:(MouoBaseController *)controller {
    //商家详情进入
    if ([scheme containsString:@"shopDetal"]) {
        NSLog(@"scheme地址:%@",scheme);
        NSString *userId = [self getParamByName:@"userId" URLString:scheme];
        return [self gotoShopController:@{@"Id":userId} controller:controller];
    }
    return nil;
}

url参数分离

+ (NSString *)getParamByName:(NSString *)name URLString:(NSString *)url
{
    NSError *error;
    NSString *regTags=[[NSString alloc] initWithFormat:@"(^|&|\\?)+%@=+([^&]*)(&|$)", name];
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regTags
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:&error];
    
    // 执行匹配的过程
    NSArray *matches = [regex matchesInString:url
                                      options:0
                                        range:NSMakeRange(0, [url length])];
    for (NSTextCheckingResult *match in matches) {
        NSString *tagValue = [url substringWithRange:[match rangeAtIndex:2]];  // 分组2所对应的串
        return tagValue;
    }
    return @"";
}

html源码



    
        
        

        
    
    
        
        陌友App进入

        

    



你可能感兴趣的:(iOS 网页进入APP)