MLWeChatUtils Class Reference

Inherits from NSObject
Declared in MLWeChatUtils.h

Overview

Provides utility functions for working with Wechat in a MaxLeap application.

This class is currently for iOS only.

Interacting With WeChat

+ initializeWeChatWithAppId:appSecret:wxDelegate:

Initializes MaxLeap WeChat Utils.

+ (BOOL)initializeWeChatWithAppId:(NSString *)appId appSecret:(NSString *)appSecret wxDelegate:(id<WXApiDelegate>)delegate

Parameters

appId

Your wechat app key.

appSecret

Your wechat app secret.

delegate

The WXApi delegate to handle wechat request and response.

Return Value

Return the value returned by [WXApi registerApp:]

Discussion

Warning: You must invoke this in order to use the WeChat functionality in MaxLeap.

Warning: The apis below are only available when [WXApi regiterApp:] successfully.

Declared In

MLWeChatUtils.h

Logging In

+ loginInBackgroundWithScope:block:

Asynchronously logs in a user using WeChat with scopes.

+ (void)loginInBackgroundWithScope:(nullable NSString *)scope block:(nullable MLUserResultBlock)block

Parameters

scope

The API scopes requested by the app in a list of comma-delimited, case sensitive strings.

block

The block to execute when the log in completes. It should have the following signature: ^(MLUser *user, NSError *error).

Discussion

This method delegates to the WeChat SDK to authenticate the user, and then automatically logs in (or creates, in the case where it is a new user) a MLUser. The onResp: method defined in WXApiDelegate protocol should be implemented and [MLWeChatUtils handleAuthorizeResponse:] should be called when the delegate receive SendAuthResp.

Declared In

MLWeChatUtils.h

+ handleAuthorizeResponse:

Handle the wechat authenticate response to complete the login process.

+ (void)handleAuthorizeResponse:(SendAuthResp *)authorizeResponse

Parameters

authorizeResponse

The SendAuthResp received in WXApiDelegate method ‘onResp:’.

Discussion

This method result in a MLUser logging in or creating. And then the block in method loginInBackgroundWithScope:block: or linkUserInBackground:withScope:block: will be excuted on main thread. You should call this method when receive the SendAuthResp response.

Declared In

MLWeChatUtils.h

+ loginInBackgroundWithAccessToken:block:

Logs in a user using wechat. Allows you to handle user login to wechat, then provide authentication data to log in (or create, in the case where it is a new user) the MLUser.

+ (void)loginInBackgroundWithAccessToken:(MLWeChatAccessToken *)token block:(nullable MLUserResultBlock)block

Parameters

token

The wechat authentication data.

block

The block to execute. The block should have the following argument signature: (MLUser user, NSError error)

Declared In

MLWeChatUtils.h

Linking Users

+ linkUserInBackground:withScope:block:

Asynchronously links wechat with scopes to an existing MLUser.

+ (void)linkUserInBackground:(MLUser *)user withScope:(NSString *)scope block:(nullable MLBooleanResultBlock)block

Parameters

user

User to link with wechat.

scope

The API scopes requested by the app in a list of comma-delimited, case sensitive strings.

block

The block to execute when the linking completes. It should have the following signature: ^(BOOL succeeded, NSError *error).

Discussion

This method delegates to the WeChat SDK to authenticate, and then automatically links the account to the MLUser. It will also save any unsaved changes that were made to the user.

Declared In

MLWeChatUtils.h

+ linkUserInBackground:withAccessToken:block:

Asynchronously links Wechat with authentication data to an existing MLUser.

+ (void)linkUserInBackground:(MLUser *)user withAccessToken:(MLWeChatAccessToken *)token block:(nullable MLBooleanResultBlock)block

Parameters

user

User to link with wechat

token

The wechat authentication data

block

The block to execute when the linking completes. It should have the following signature: ^(BOOL succeeded, NSError *error).

Declared In

MLWeChatUtils.h

+ unlinkUserInBackground:block:

Unlinks the MLUser from a Wechat account asynchronously.

+ (void)unlinkUserInBackground:(MLUser *)user block:(nullable MLBooleanResultBlock)block

Parameters

user

User to unlink from Wechat.

block

The block to execute. It should have the following argument signature: ^(BOOL succeeded, NSError *error).

Declared In

MLWeChatUtils.h

Getting Linked State

+ isLinkedWithUser:

Whether the user has their account linked to wechat.

+ (BOOL)isLinkedWithUser:(nullable MLUser *)user

Parameters

user

User to check for a wechat link. The user must be logged in on this device.

Return Value

YES if the user has their account linked to wechat, otherwise NO.

Declared In

MLWeChatUtils.h