跳转

NSURL *wechat URL = [NSURL URLWithString:@"wechat://"];
if ([[UIApplication shareApplication] canOpenURL:wechatURL])) {
    [UIApplication shareApplication] openURL:wechatURL];
}

URL : union resource locator
scheme + path + port wechat:// 可以为空

- (BOOL)application:(UIApplication )application openURL:(NSURL )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
UINavigationController rootNav = (UINavigationController)self.window.rootViewController;
//拿到栈顶控制器, 先pop
[rootNav popToRootViewController];
ViewController homeVC = [rootNav.childViewController firstObject];
  NSString urlStr = url.absoluteString;
  if ([urlStr containString:@"timeline"]) {
      //跳转
      [homeVC performSegueWithIdentifier:@"xxx" sender:nil];
  } 
}

跳回

wechat://timeline:news
把url传给控制器,

NSString* urlStr = [[self.urlStr componentsSeperateByString:@"?"] lastObject]; 
urlStr = [urlStr stringByAppendingString:@"//:"];
if ([[UIApplication shareApplication] canOpenURL:wechatURL])) { 
    [UIApplication shareApplication] openURL:wechatURL]; 
}

OC调用Javascript

evaluateJavascriptByString:xxx
Javascript 调用OC

location.href
shouldStartLoadWithRequest:(NSURLRequest) request { NSString url = request.URL.absoluteString; NSString* metodName = nil; if ([url hasPrefix:@"FB://"]) { NSLog(@"执行代码"); metodName = [url subStringFromIndex:4]; [self performanceSelector:NSSelectorFromString(metodName) withObject:nil]; }
return true;
}

results matching ""

    No results matching ""