相应的 universal link 也都配置完成,Safari中输入域名可以看到相关跳转, 以及info.list中相关的值也都已设置 但还是有问题
ios使用微信登录sdk可以拉起微信但是闪一下就退了,无法正确获取授权页面该怎么办?环境描述:系统IOS 12.4 ,微信版本 7.0.8, SDK 1.8.6, 错误日志: Error:set token fail, errCode:4, errLog:wx token[] or contextId[(null)] is nil 状态描述:可以看到有跳转微信的过程,但是不能正确获取微信授权界面。但是又能拿到相应的返回值,很奇怪,有人遇到过嘛? 相关代码: //三个重写的API func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { returnWXApi.handleOpen(url, delegate: self) // func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { // return WXApi.handleOpen(url, delegate: self) // } func application(_application: UIApplication, handleOpen url: URL) -> Bool{ returnWXApi.handleOpen(url, delegate: self) func application(_ application: UIApplication, continueuserActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { logger.info("调用useractivity" returnWXApi.handleOpenUniversalLink(userActivity, delegate: self) //回调 func onResp(_ resp: BaseResp) { logger.info(String(format: "返回的resp是:%p", resp)) //微信登录 ifresp is SendAuthResp { logger.info("微信登录接口" // switch(resp.errCode){ // case 0: // let response = resp as! SendAuthResp // NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WXLoginSuccessNotification"), object: response.code) // break // case -4: //用户拒绝 // NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WXLoginDenyNotification"), object: nil) // break // case -2: //用户取消 // NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WXLoginCancelNotification"), object: nil) // break // default: // break // } ifresp.errCode == 0 && resp.type == 0 {//授权成功 let response = resp as! SendAuthResp NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WXLoginSuccessNotification"), object: response.code) // end of internal if return // end of external if // end of onResp // send @IBAction func wechatLogin(_ sender: LGButton) { sender.isLoading = true ifWXApi.isWXAppInstalled() { let app = UIApplication.shared ifapp.canOpenURL(URL.init(string: WEIXIN_SCHEME)!) { let req = SendAuthReq.init() req.scope = "snsapi_message,snsapi_userinfo,snsapi_friend,snsapi_contact" req.state = "\(arc4random()%100)" logger.info("准备开启微信登录!" let deadlineTime = DispatchTime.now() + .seconds(1) DispatchQueue.main.asyncAfter(deadline: deadlineTime) { //停止转圈圈 WXApi.send(req, completion: { (success) in sender.isLoading = false logger.info("成功获取微信app的授权,开始向微信服务器发起请求!" })} } else if#available(iOS 10.0, *) { UIApplication.shared.open(URL.init(string: "http://weixin.qq.com/r/qUQVDfDEVK0rrbRu9xG7")!, options: [:], completionHandler: nil) } else // Fallback on earlier versions UIApplication.shared.openURL(URL.init(string: "http://weixin.qq.com/r/qUQVDfDEVK0rrbRu9xG7")!) else self.sendmsgToWxServer() sender.isLoading = false // 登录成功之后 @objc func WXLoginSuccess(notification:Notification) { logger.info("WXLoginSuccess开始执行" let code = notification.object as! String let requestUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=\(WX_APPID)&secret=\(WX_APPSecret)&code=\(code)&grant_type=authorization_code" DispatchQueue.global().async { let requestURL: URL = URL.init(string: requestUrl)! let data = try? Data.init(contentsOf: requestURL, options: Data.ReadingOptions()) //TODO: 从微信获取到的用户信息,然后再回传到app的后台服务器 DispatchQueue.main.async { let jsonResult = try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<String,Any> logger.info("微信app传回来的数据: \(jsonResult)" let openid: String = jsonResult["openid"] as! String let access_token: String = jsonResult["access_token"] as! String let unionid: String = jsonResult["unionid"] as! String self.openid = openid //向app服务器保存用户的openid和access_token let parameters: Parameters = ["openId": openid, "accessToken": access_token] AF.request(SAVE_USER_INFO_URL_STR, parameters: parameters).validate() let homeVcUrlStr = String(format: "%@%@", arguments: [HOMEPAGE_LOGINED_URL_STR, unionid]) logger.info(String(format:"homeStr: %@, openid: %@", arguments:[homeVcUrlStr, openid])) let mainNavigationController = self.presentingViewController as! LFMainNavigationController let homePageController = mainNavigationController.viewControllers[0] as! LFHomeViewController homePageController.openid = self.openid homePageController.homePageUrlStr = homeVcUrlStr self.dismiss(animated: true, completion: { }) // end of dismiss //暂时不需要从微信服务器获取用户的信息 // self.getUserInfo(openid: openid, access_token: access_token) 有人能帮忙看看嘛? 或者有人遇到相似的问题嘛 ? 求交流 !!! 网页回复不及时可加微信:dzjMichael ( 加时注明来源 不甚感激!!! ———————————————————————————— 2020 - 01 -07更新 问题已经解决,发现是UL配置的问题,建议各位老铁多多检查自己的配置吧,从scheme到ul,然后再试自己的代理函数,基本上照着文档来一般不会有问题。
2019-10-29同样遇到这个问题,onResq不回调 环境:swift5 设备: ios12.4.1 ipad 微信:7.0.8 微信日志显示: wxlog:Error:fail to load Keychain status:-25300, keyData null:1 有人解决了嘛?或者说 如何调试定位真正的问题啊? 万分感谢 !
ios sdk 1.8.6.1 授权登录没有回调 onResp ?IOS SDK 1.8.6.1 SendAuthReq 调用之后 如果是确定授权 onResp 会被正常吊起,正常回调 APP。 问题 1. 如果是取消(拒绝授权) onResp 没有被 调用?并且就停留在微信页面,不回调 APP 问题 2. app 被回调走的 openurl 方法不是 link 方法 (link 已经配置) 问题 3 请确认吊起的页面是否正确 问题 4 apple-app-site-association文件是否正确? { "applinks": { "apps": [], "details": [ { "appID": "******.com.goockr.********",(可以确保是 teamid.bundleid) "paths": [ "*" ] } ] } } 环境 微信 7.0.8 ios 13.1.1 微信 appid wxf54b36ad0a35ce54 打印日志 2019-10-15 14:50:18.542662+0800 GoockrCharging[509:45639] wxlog : wxlog:send req[<SendAuthReq: 0x28255d890>], appID:wxf54b36ad0a35ce54, universalLink:https://chhp.goockr.com/, sdkVersion:1.8.6.1 2019-10-15 14:50:18.563918+0800 GoockrCharging[509:45639] wxlog : wxlog:set property list 2019-10-15 14:50:18.596720+0800 GoockrCharging[509:45639] wxlog : wxlog:Error:fail to load Keychain status:-25300, keyData null:1 2019-10-15 14:50:18.596814+0800 GoockrCharging[509:45639] wxlog : wxlog:Error:token[(null)] is null 2019-10-15 14:50:18.629768+0800 GoockrCharging[509:45639] wxlog : wxlog:launch app with ul only success 2019-10-15 14:50:18.629883+0800 GoockrCharging[509:45639] wxlog : wxlog:launch app with universal link, ret:1 2019-10-15 14:50:18.629944+0800 GoockrCharging[509:45639] wxlog : wxlog:req:<SendAuthReq: 0x28255d890>, cid:c3dd703a982028a5a3115d55e707118bbc9d2522 2019-10-15 14:50:18.796704+0800 GoockrCharging[509:46989] PBItemCollectionServicer connection disconnected. 2019-10-15 14:50:19.463485+0800 GoockrCharging[509:45639] Can't end BackgroundTask: no background task exists with identifier 6 (0x6), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. 以下页面是授权登录吊起的页面 是否正确? [图片]
2019-10-16