欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  互联网

swift 原生做微信分享

程序员文章站 2022-03-13 21:41:36
接入:class AppDelegate{WXApi.registerApp("", universalLink: "https://.cn/")func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return WXApi.handleOpen(url, delega...

接入:

class AppDelegate{

WXApi.registerApp("", universalLink: "https://.cn/")


func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        
        return WXApi.handleOpen(url, delegate: self)
        
       
    }
    
    
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        return WXApi.handleOpenUniversalLink(userActivity, delegate: self)
    }



}




extension AppDelegate: WXApiDelegate{
    func onReq(_ req: BaseReq) { }
    
    
    func onResp(_ resp: BaseResp) {
        if let response = resp as? SendAuthResp, response.errCode == 0, let code = response.code{
            print(code)
        }
    }
}

 

打 log

            WXApi.startLog(by: .detail) { (info) in
                print(info)
            }

分享文字

            let req = SendMessageToWXReq()
            req.bText = true;
            req.text = "分享的内容"
            req.scene = Int32(WXSceneSession.rawValue)
            WXApi.send(req) { ( ok ) in
                print(ok)
            }

分享网页

            let webpageObject = WXWebpageObject()
            webpageObject.webpageUrl = "https://open.weixin.qq.com";
            let message = WXMediaMessage()
            message.title = "标题";
            message.description = "描述";
            message.setThumbImage(UIImage(named: "default_avatar")!)
        
            message.mediaObject = webpageObject;
            let req = SendMessageToWXReq()
            req.bText = false
            req.message = message;
            req.scene = Int32(WXSceneSession.rawValue);
            WXApi.send(req) { ( hah ) in
                print(hah)
            }

分享小程序

            let object = WXMiniProgramObject()
            object.webpageUrl = "http://www.baidu.com"
            object.userName = ""
            object.path = "pages/payment/payment"
            object.hdImageData = UIImage(named: "default_avatar")?.pngData()
            
            object.miniProgramType = .test
            let message = WXMediaMessage()
            message.title = "小程序标题"
            message.description = "小程序描述"
            message.thumbData = nil
            
            let req = SendMessageToWXReq()
            req.bText = false
            req.message = message
            req.scene = Int32(WXSceneSession.rawValue)
            //目前只支持会话
            WXApi.send(req) { ( hah ) in
                print(hah)
            }

 

本文地址:https://blog.csdn.net/dengjiangszhan/article/details/110624782

相关标签: ios