我在LoginViewController添加一個按鈕。 這裏是LoginViewComtrolleriOS無法識別的選擇器發送到實例錯誤
loginButton?.addTarget(self, action: #selector(LoginViewController.wechatLogin), for: .touchDown)
func wechatLogin() {
sendWXAuthRequest()
}
func sendWXAuthRequest() {
print("hello")
let req: SendAuthReq = SendAuthReq()
req.scope = "snsapi_userinfo,snsapi_base"
WXApi.send(req)
}
func onResp(_ resp: BaseResp!) {
print(resp)
}
代碼在這裏是代碼AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//register
buildKeyWindow()
let right = WXApi.registerApp("My_Appid")
print(right)
return true
}
func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
return WXApi.handleOpen(url, delegate: self)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return WXApi.handleOpen(url, delegate: self)
}
當我第一次運行該應用程序,有一個錯誤顯示,當我進入微信。 然後我第二次運行它,有一些錯誤,說「無法識別的選擇發送到實例」
當我註釋掉WXApi.registerApp(「My_Appid」)。除了啓用按鈕,一切都可以。 –