美文网首页
swift4 接微信SDK 登录

swift4 接微信SDK 登录

作者: de_fly | 来源:发表于2018-05-15 14:38 被阅读17次

1. appKey

2. import openSDK  

3.project-Bridging-Header.h 里面导入 微信 SDK 的头文件

#import "WXApi.h"

#import "WXApiObject.h"

4. 在 Appdelegate 里面  配置 SDK 继承协议 发送返回的结果

extension AppDelegate: WXApiDelegate {

fun cconfigWeChat() {

        WXApi.registerApp(SDKConstant.weiXinAppID)

    }

    fun capplication(_app:UIApplication, open url:URL, options: [UIApplicationOpenURLOptionsKey:Any] = [:]) ->Bool{

        returnWXApi.handleOpen(url, delegate:self)

    }

    fun capplication(_application:UIApplication, open url:URL, sourceApplication:String?, annotation:Any) ->Bool{

        WXApi.handleOpen(url, delegate:self)

        return true

    }

    fun conResp(_resp:BaseResp!) { // 使用通知的方式

            ifresp.errCode== 0 && resp.type== 0 {//授权成功

            letresponse = respas!SendAuthResp

            NotificationCenter.default.post(name: weChatLoginNotification, object: response.code)

        }

    }

    func onReq(_req:BaseReq!) {

    }

}

5. LoginViewController 里面

 /**  微信通知 登录 */

  @objc  func WXLoginSuccess(_notification:Notification) {

    letcode = notification.objectas!String

// 拿到 code 就可以了 

// 其它的 可以交给服务端处理

    }

相关文章

网友评论

      本文标题:swift4 接微信SDK 登录

      本文链接:https://www.haomeiwen.com/subject/ainedftx.html