Skip to content

QIMSDK Scheme跳转说明

Lidalu edited this page Dec 16, 2018 · 1 revision

QIMSDK scheme解析及跳转说明

  1. QIMSDK 所有的scheme示例见IMSDK-iOS文件夹中的open_scheme.html文件

  2. 按照QIMSDK_iOS_Scheme.html中的scheme格式来填写宿主App方需要的scheme

  3. 在UIWebView方法 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;中对scheme进行拦截并实现跳转

  4. scheme拦截例子代码如下

     if (schemaUrl.absoluteString.length > 0 && [schemaUrl.scheme isEqualToString:@"qtalkaphone"]) {
    
         NSArray *components = [schemaUrl.absoluteString componentsSeparatedByString:@":"];
         
         NSString *host = [schemaUrl host];
         
         if ([host isEqualToString:@"qunarchat"]) {
         
             NSString *path = [schemaUrl path];
             
             if ([path isEqualToString:@"/openGroupChat"]) {
                 
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSString *groupId = [tempDic objectForKey:@"jid"];
    
                 
             } else if ([path isEqualToString:@"/openSingleChat"]) {
                 
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSString *userId = [tempDic objectForKey:@"jid"];
                 NSString *realJid = [tempDic objectForKey:@"realJid"];
                 
             } else if ([path isEqualToString:@"/headLine"]) {
                 
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSString *jid = [tempDic objectForKey:@"jid"];
    
             } else if ([path isEqualToString:@"/openGroupChatInfo"]) {
                 
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSString *groupId = [tempDic objectForKey:@"groupId"];
                 
             } else if ([path isEqualToString:@"/openSingleChatInfo"]) {
                 
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSString *jid = [tempDic objectForKey:@"userId"];
                 NSString *realJid = [tempDic objectForKey:@"realJid"];
                 
             } else if ([path isEqualToString:@"/openUserCard"]) {
                 
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSString *jid = [tempDic objectForKey:@"jid"];
                 if (jid.length > 0) {
    
                 }
             } else if ([path isEqualToString:@"/hongbao"]) {
                 //我的红包
           
             } else if ([path isEqualToString:@"/hongbao_balance"]) {
                 
                 //余额查询
         
             } else if ([path isEqualToString:@"/account_info"]) {
                 
             } else if ([path isEqualToString:@"/unreadList"]) {
                 
             } else if ([path isEqualToString:@"/publicNumber"]) {
                 
             } else if ([path isEqualToString:@"/openOrganizational"]) {
                 
             } else if ([path isEqualToString:@"/myfile"]) {
                 
             } else {
                 
             }
         } else if ([host isEqualToString:@"rnsearch"]) {
             
         } else if ([host isEqualToString:@"router"]) {
             
             NSString *path = [schemaUrl path];
             if ([path isEqualToString:@"/openHome"]) {
                 NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
                 NSInteger selectIndex = [[tempDic objectForKey:@"tab"] integerValue];
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"kNotifySelectTab" object:@(selectIndex)];
             }
         } else if ([host isEqualToString:@"rnservice"]) {
             
             NSDictionary *tempDic = [self parseURLQuery:schemaUrl];
             QIMVerboseLog(@"打印Schema参数列表生成的字典:\n%@", tempDic);
             NSString *module = [tempDic objectForKey:@"module"];
             NSString *Screen = [tempDic objectForKey:@"Screen"];
             
             
         } else if ([host isEqualToString:@"qrcode"]) {
             
         } else if ([host isEqualToString:@"logout"]) {
             
         } else if ([host isEqualToString:@"accountSwitch"]) {
             
             
         } else {
         
         }
     }
    
     
     - (NSDictionary *)parseURLQuery:(NSURL *)url {
     	NSString *query = url.query;
     	NSArray *subArray = [query componentsSeparatedByString:@"&"];
    	 	NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithCapacity:4];
     
     	for (int j = 0 ; j < subArray.count; j++) { 
     	
         //在通过=拆分键和值
         NSArray *dicArray = [subArray[j] componentsSeparatedByString:@"="];
         //给字典加入元素
         NSString *value = [[dicArray objectAtIndex:1] URLDecodedString];
         NSString *key = [[dicArray objectAtIndex:0] URLDecodedString];
         if (key && value) {
             [tempDic setObject:value forKey:key];
         }
     }
         return tempDic;
     }
    
  5. 对照QIMSDK文件夹中的QIMSDKHelper+UI.h头文件注释,获取对应的VC,实现scheme跳转(scheme跳转之前务必保证已经登录成功

    示例:

    获取与san.zhang@voip.com的对话框,并实现跳转

     UIViewController *chatVc = [[QIMSDKHelper sharedInstance] getSingleChatVCByUserId:@"san.zhang@voip.com"];
     [self.navigationController pushViewController:chatVc animated:YES];
    
Clone this wiki locally