I add a button at the LoginViewController. Here is the code in 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)
}
Here is code in 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)
}
When I first run the application, there is a error show when I get into WeChat. Then I second run the it, there is a some error which said "unrecognized selector sent to instance"
Try to change -all_load
to -force_load
in Other Linker Flags
of your Buliding settings