IOS share to WeChat Swift

The main contents include the steps to integrate WeChat SDK, how to pass Swift calls, and how to implement a share. Demo encapsulates a ShareManager that enables quick sharing of text, pictures, and links to WeChat.


Step 1

Register application ID on WeChat open platform, get AppID.

WeChat needs auditing for new applications, and typically 7 business days. AppID borrowed WeDemo’s Demo.

Step 2

  1. Add URL schemes to AppID so that WeChat can callback your app. IOS share to WeChat Swift
  2. Add white list in info.plist, otherwise you will be wrong -canOpenURL: failed for URL IOS share to WeChat Swift
    in WeChat environment (such as simulator)

Step 2

  1. Integrated WeChat SDK pod CocoaPods through’WechatOpenSDK’
  2. Adding Objective-C Bridging Header
    requires confirmation that the path of bridging header is added in the Building setting – Swift Compiler – Code Generation. For example, “YourApp/YourApp-Bridging-Header.h.””
  3. Add the following code #import “WXApi.h” in YourApp-Bridging-Header.h, and then use the relevant method directly in the Swift file without import.


  1. Registered third party application func application to WeChat terminal program (_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? -&gt); Bool WXApi.registerApp (“APP-ID”) {return true}
  2. Send a request to the WeChat
    process: create a multimedia message (WXMediaMessage) or rich text (String) message, and then create an SendMessageToWXReq request, and finally through the WXApi.send () method request to WeChat.
  3. WeChat responded to
    onResp protocol implementation method of func onResp (resp: BaseResp _!)} {/ / treatment response


Repo address

Share text (text, ShareManager.shared.sendText / inScene: / WXSceneSession) ShareManager.shared.sendImage (imageData, inScene: share pictures WXSceneTimeline) / / share links to pages let url = "" ShareManager.shared.sendLink (URL, text, inScene:, WXSceneSession)