WeChat iOS SDK Guide  1.0
 All Class Function Property
WeChat iOS SDK Guide: Document

How to use WeChat SDK

  1. Register your application ID in WeChat
  2. Download WeChat SDK file
  3. Add the following files in SDK file to your project: libWeChatSDK.a, WXApi.h, WXApiObject.h
  4. Add statements to register your ID on WeChat while starting the app:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [WXApi registerApp:"wxd930ea5d5a258f4f"]; 
  5. Rewrite handleOpenURL and openURL methods of AppDelegate
    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [WXApi handleOpenURL:url delegate:self]; }
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [WXApi handleOpenURL:url delegate:self]; }
  6. Methods to implement WXApiDelegate agreement:
    - (void) onReq:(BaseReq*)req
    - (void) onResp:(BaseResp*)resp
  7. Example - Send an image to WeChat:

    - (void) sendImageContent { WXMediaMessage *message = [WXMediaMessage message]; [message setThumbImage:[UIImage imageNamed:"res2.jpg"]];
       WXImageObject *ext = [WXImageObject object]; NSString *filePath = [[NSBundle mainBundle] pathForResource:"res2" ofType:@"jpg"]; ext.imageData = [NSData dataWithContentsOfFile:filePath] ;
       message.mediaObject = ext;
     SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease]; req.bText = NO; req.message = message;
     [WXApi sendReq:req]; }
  8. Example - response received from WeChat:
    -(void) onResp:(BaseResp*)resp
        if([resp isKindOfClass:[SendMessageToWXResp class]])
            NSString *strMsg = [NSString stringWithFormat:"Result:d", resp.errCode];
  9. For more examples, please see WeChat SDK Sample Demo.