Swift打开QQ或者TIM聊天页面

1、在info.plist文件新增 LSApplicationQueriesSchemes 字段配置参考http://wiki.mob.com/6803-2/白名单(TIM和qq的必须添加)

2、相关代码

    if(UIApplication.shared.canOpenURL(URL(string: "mqq://")!)){
        let str =  String(format: "mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web", qq)
        UIApplication.shared.openURL(URL(string: str)!)
    }else if (UIApplication.shared.canOpenURL(URL(string: "tim://")!)){
        let str =  String(format: "tim://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web", qq)
        UIApplication.shared.openURL(URL(string: str)!)
    }

你可能感兴趣的:(Swift打开QQ或者TIM聊天页面)