Branch.io validateReferralCode() 和 applyReferralCode() 的区别?

Difference between Branch.io validateReferralCode() and applyReferralCode()?

我正在使用 Branch.io 作为推荐代码。我看到两种方法似乎适用于我想做的事情,但是,这两种方法的描述似乎相同。在 Branch.io 的上下文中,如何确认用户输入了正确的推荐代码?

分支文档:https://github.com/BranchMetrics/Branch-Android-SDK#register-an-activity-for-direct-deep-linking-optional-but-recommended

根据文档,有两种方法可以使用,validateReferralCode() 和 applyReferralCode()。两者的实现如下。

Branch branch = Branch.getInstance(getApplicationContext());
branch.validateReferralCode(code, new BranchReferralInitListener() {
    @Override
    public void onInitFinished(JSONObject referralCode, Branch.BranchError error) {
        try {
            if (!referralCode.has("error_message")) {       // will change to using a second callback parameter for error code soon!
                String referral_code = referralCode.getString("referral_code");
                if (referral_code.equals(code)) {
                    // valid
                } else {
                    // invalid (should never happen)
                }
            } else {
                // invalid
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
});

还有……

Branch branch = Branch.getInstance(getApplicationContext());
branch.applyReferralCode(code, new BranchReferralInitListener() {
    @Override
    public void onInitFinished(JSONObject referralCode, Branch.BranchError error) {
        try {
            if (!referralCode.has("error_message")) {
                // applied. you can get the referral code amount from the referralCode JSONObject and deduct it in your UI.
            } else {
                // invalid code
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
});

文档中的描述如下,

Validate referral code

Validate if a referral code exists in Branch system and is still valid. A code is vaild if:

It hasn't expired. If its calculation type is uniqe, it hasn't been applied by current user. If valid, returns the referral code JSONObject in the call back.

并申请推荐码

Apply referral code

Apply a referral code if it exists in Branch system and is still valid (see above). If the code is valid, returns the referral code JSONObject in the call back.

这些有什么区别?

在Branch的系统中,您可以指定一个referral code为一次性使用(意思是有人叫apply更早)。如果您需要事先查看此值,请使用验证推荐代码方法。

应用,当然是将代码应用到用户的余额中。如果您创建了唯一类型的推荐代码,则 Apply 将失败。在呈现给用户或应用代码之前先验证代码是一种很好的做法。