Installation Guide

Build your First Application with WeChat SDK!

Note: This document only introduces how to use WeChat SDK and you requrie a basic knowledge of Eclipse IDE.

  1. 1. Apply for App ID

    Fill in the required details on the App Registration page to obtain an AppID. Submit the registered app for approval. Approved apps will be released.

  2. 2. Download the WeChat client development kit

    The development kit comprises three parts:

    • libammsdk.jar (import the sdk library so your app can communicate with WeChat);
    • API Document (for reference);
    • Sdesktop widget source code (encapsulates the UI tool classes and UI style).

    Note that only libammsdk.jar is necessary.

    Download: AndroidPlatform development kit

  3. 3. Build the development environment

    [1] Build your project in Eclipse.

    [2] Create a libs directory. Then copy libammsdk.jar from the development kit in libs to the new directory. In the example below, the user creates a project called SDK_Sample and then copies the jar package into the libs directory.

    Android Guide : Build your development environment

    [3] Right-click the project and select "Build Path" >"Configure Build Path..." >"Libraries". Use "Add Jars..." to import libammsdk.jar from libs as shown below.

    Android Guide : Build your development environment

    Import the related classes you want to use from WeChat API files as follows:

    import com.tencent.mm.sdk.openapi.WXTextObject;
  4. 4. Use the development kit in code

    [1] Registering on WeChat

    Register your WeChat app ID via your code to enable WeChat to respond to your app. Registering your app ID at the program entry point (or other suitable location) enables the WeChat onCreate Activity function, as shown below.

    Android Guide : Build your development environment

    [2]Send a request or respond to WeChat

    Use sendReq and sendResp based on IWXAPI so your app can send a request or respond to WeChat.

    boolean sendReq(BaseReq req);

    sendReq: The app sends messages to WeChat and then returns to the app after a messages is sent.

    boolean sendResp(BaseResp resp);

    sendResp: WeChat requests data from the app and then returns to WeChat when the app responds.

    An example of sendReq implementation is shown below:

    Android Guide : Build your development environment

    Note:

    Set the scene parameter SendMessageToWX.Req to

    • (1) WXSceneSession (default) to send messages through WeChat Chats or
    • (2) As a WXSceneTimeline to post the message on Moments (available for WeChat 4.2 and later versions).
    • To check whether the WeChat version supports your app API, call getWXAppSupportAPI under IWXAPI. SDK 1.1 and later versions support posting on Moments.

    Implementing InsendResp is similar to implementing SendReq, as shown below:

    Android Guide : Build your development environment

    App developers define specific content. For details, see the SDK Sample Demo source code in the WeChat Development Kit.

    [3] Receive requests and responses from WeChat

    Perform the following steps so your app can receive requests and responses from WeChat:

    a. Create a wxapi directory in your package and add a WXEntryActivity class inherited from Activity.

    For example, if the app package is net.sourceforge.simcpux

    Android Guide : Build your development environment

    , add exported parameter (set to True) in the manifest file.

    Android Guide : Build your development environment

    b. Implement the IWXAPIEventHandler interface. Requests sent by WeChat will be called back by onReq. Responses from WeChat will be called back by onResp.

    c. In WXEntryActivity, pass the received intent and the object on which the IWXAPIEventHandler interface is implemented to handleIntent based on IWXAPI, as shown below:

    Android Guide : Build your development environment

    On the IWXAPIEventHandler, interface WeChat uses onReq to perform call back after sending a request to an app, and uses onResp after responding to the request from an app.

    Note:

    If you use obfuscated code, add the following to proguard.cfg to ensure that your app runs properly:
    • - keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}
    • - keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}

Note: This document describes how to develop an app using WeChat SDK. You should already be familiar with the XCode environment.

  1. 1. Register App ID

    Fill in the required details on the App Registration page to obtain an AppID. Submit the registered app for approval. Approved apps will be released.

  2. 2. Download the SDK package

    The package comprises three files: libWeChatSDK.a, WXApi.h, WXApiObject.h

    Download: iOS SDK package

  3. 3. Build your development environment

    [1] Create your project in XCode.

    [2] Add the following three files to your project: libWeChatSDK.a, WXApi.h, WXApiObject.h; for example, you can create a project called Test, and add these files to the project's directory.

    Note: For XCode 4.3 and earlier versions, please use libWeChatSDK.a. For XCode 4.5 and later versions, use libWeChatSDK_armv7_v7s.a

    iOS Guide : Build your development environment

    [3] Choose the "Build Setting". Then add the paths of the following files to "Search Paths", as shown below: libWeChatSDK.a, WXApi.h, WXApiObject.h.

    Note: For XCode 4.3 and earlier versions, use libWeChatSDK.a. for XCode 4.5 and later versions, please use libWeChatSDK_armv7_v7s.a

    iOS Guide : Build your development environment

    [4] In Xcode4, select "TARGETS">"Info">"URL type">"URL scheme". Add the ID for your registered app. For Xcode3 and earlier versions, please add the ID to your plist file, as shown below.

    iOS Guide : Build your development environment iOS Guide : Build your development environment

    URL scheme settings in Xcode4

    [5] For files on which you want to use the WeChat API, import WXApi.h and add the WXApiDelegate protocol.

    #import <UIKit/UIKit.h>
    #import "WXApi.h"
    @interface AppDelegate : UIResponder <UIApplicationDelegate, WXApiDelegate>
    @property (strong, nonatomic) UIWindow *window;
    @end
    
  4. 4. Start Coding

    Now go ahead and start coding!