【问题标题】:iOS unrecognized selector sent to instance erroriOS无法识别的选择器发送到实例错误
【发布时间】: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") 时。一切都很好,除了按钮是启用的。

标签: ios swift wechat


【解决方案1】:

尝试在您的建筑设置的Other Linker Flags 中将-all_load 更改为-force_load

【讨论】:

  • 这里使用Xcode 8.3和微信iOS SDK 1.7.7,-Obj-c-force_load都不起作用,但是-all_load解决了问题。
猜你喜欢
  • 2011-12-24
  • 2012-03-14
  • 1970-01-01
  • 2014-02-18
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多