auth method

void auth({
  1. required SharePlatform platform,
  2. required dynamic authCall(
    1. SharePlatform platform,
    2. AuthResultType resultType,
    3. Map<String, dynamic> authMap
    ),
})

授权 platform 平台类型 authCall 授权回调

Implementation

void auth(
    {required SharePlatform platform,
    required Function(SharePlatform platform, AuthResultType resultType, Map<String, dynamic> authMap) authCall}) {
  CloudChannelManager.instance.send(_authShareSdkMethodName, arguments: {
    "platform": platform.name,
  }).then((resultMap) {
    var status = "${resultMap["status"] ?? ""}";
    if (status == "success") {
      if (platform == SharePlatform.apple) {
        var dataJson = JsonUtils.toJson(resultMap["data"] ?? {});
        authCall(platform, AuthResultType.success, JsonUtils.fromJson(dataJson));
      } else if (platform == SharePlatform.wechat) {
        var wechatResult = WechatResult();
        var dataJson = JsonUtils.toJson(resultMap["data"] ?? {});
        var authInfo = wechatResult.analysisAuthInfo(dataJson);
        authCall(platform, AuthResultType.success, authInfo);
      }
    } else if (status == "cancel") {
      authCall(platform, AuthResultType.cancel, {});
    } else if (status == "error") {
      authCall(platform, AuthResultType.error, {});
    } else if (status == "uninstall") {
      authCall(platform, AuthResultType.uninstall, {});
    }
    authCall(platform, AuthResultType.complete, {});
  });
}