尊敬的微信技术支持团队,
您好,我目前正在我们的iOS应用程序中集成微信登录功能。但是,我们遇到了一个问题,用户通过微信认证并返回应用程序后,onResp
方法没有接收到任何响应。为了解决这个问题,我们尝试了多种方法,但问题依旧未能解决。因此,我希望能得到贵团队的帮助。
期待您的回复,并提前感谢您的帮助。
下面附上代码。
请参考一下。
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, WXApiDelegate, WXApiLogDelegate {
let WECHAT_APP_ID = "wx92c4efd1665e5755"
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// flutter channel
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let channel = FlutterMethodChannel(name: "com.almightydr.meditravel/wxapi", binaryMessenger: controller.binaryMessenger)
channel.setMethodCallHandler { (call, result) in
if call.method == "wechatLogin" {
self.requestWechatLogin()
}
}
WXApi.startLog(by: WXLogLevel.detail) { log in
debugPrint(log)
}
WXApi.registerApp(WECHAT_APP_ID, universalLink: "https://ccic.almightydr.com/")
WXApi.checkUniversalLinkReady { step, result in
debugPrint(result.description)
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func wxSdkShouldReadDataFromPasteboard(_ sdk: WXApi, completion: @escaping (Bool) -> Void) {
// TODO: 여기에 클립보드를 읽는 것이 안전한지 결정하는 로직을 추가하세요.
// 예를 들어, 사용자에게 허가를 요청하거나 특정 조건을 검사할 수 있습니다.
// 이 예제에서는 항상 클립보드를 읽도록 허용하도록 설정합니다.
completion(true)
}
func onLog(_ log: String, logLevel level: WXLogLevel) {
debugPrint("onLog: " + log)
}
func requestWechatLogin() {
debugPrint("call requestWechatLogin")
let req = SendAuthReq()
req.scope = "snsapi_userinfo"
req.state = "wechat_ios"
WXApi.send(req) { ret in
if (ret) {
debugPrint("sent")
} else {
debugPrint("failed sent")
}
}
}
override func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
debugPrint("handlOpen")
return WXApi.handleOpen(url, delegate: self)
}
override func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
debugPrint("open url")
return WXApi.handleOpen(url, delegate: self)
}
override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
debugPrint("handleOpenUniversalLink")
return WXApi.handleOpenUniversalLink(userActivity, delegate: self)
}
func onResp(_ resp: BaseResp) {
debugPrint("onResp")
if resp.isKind(of: PayResp.self) {
let response = resp as! PayResp
switch response.errCode {
case WXSuccess.rawValue:
debugPrint("支付成功")
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "wechat_pay_success"), object: nil)
default:
debugPrint("支付失败")
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "wechat_pay_fail"), object: nil)
}
}
}
func onReq(_ req: BaseReq) {
// TODO
debugPrint("onReq")
}
}