After you integrate the WindVane or uni-app miniapp container into a native app, you can associate a user who login to the app with the miniapp container during runtime.
Unless the app user has not logged in yet, when the app user logs in or switches accounts, the app must associate the logged in user with the miniapp container at runtime. After association, the mini program container will use the user information (only UserId) in the following scenarios:
Determine whether the current user has the corresponding device authorization
When switching users, the SDK will automatically clear the WindVane miniapp's cookies based on whether the user information has changed
When reporting PV, UV and other data (reporting plugin needs to be introduced)
Using the whitelist grayscale function of mini programs on open application platforms
Associate a user with a miniapp container
To use the whitelist-based canary release feature and the automatic cache clearing feature, you must call the following interface to associate the user with the miniapp container. Sample code:
ServiceManager.getInstance().registerService(IUserInfoService.class.getName(), new IUserInfoService() {
@Override
public UserInfo getUserInfo() {
// Return user information based on the logon status. If no user is logged on, null is returned.
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userId);
return userInfo;
}
});Device authorization
private boolean isAuthorized() {
IUserInfoService userInfoService = ServiceManager.getInstance()
.getService(IUserInfoService.class.getName());
// ...
UserInfo userInfo = userInfoService.getUserInfo();
// ...
return AuthorizationManagement
.getInstance(mContext)
.isAuthorized(innerScope, userInfo.getUserId(), appId);
}
Cookie clear
private void clearMiniAppCookies(...) {
IUserInfoService userInfoService = ServiceManager.getInstance()
.getService(IUserInfoService.class.getName());
// ...
UserInfo userInfo = userInfoService.getUserInfo();
// ...
if (isDifferentUser(userInfo.getUserId())) {
clearCookie();
}
}
Data report
private void reportData(...) {
IUserInfoService userInfoService = ServiceManager.getInstance()
.getService(IUserInfoService.class.getName());
// ...
UserInfo userInfo = userInfoService.getUserInfo();
// ...
report(userInfo.getUserId());
}