【发布时间】:2017-03-03 03:32:28
【问题描述】:
我在 LoginViewController 上添加了一个按钮。 这是 LoginViewComtroller 中的代码
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") 时。一切都很好,除了按钮是启用的。