我试图使用Unity Branch SDK为我现有的应用程序添加一个分享功能。
我使用以下代码创建了短网址。
BranchUniversalObject universalObject = new BranchUniversalObject();
BranchLinkProperties linkProperties = new BranchLinkProperties();
string deviceUniqueIdentifier = SystemInfo.deviceUniqueIdentifier;
universalObject.canonicalIdentifier = $"xLeague/{deviceUniqueIdentifier}";
universalObject.canonicalUrl = "http://xleague.games/";
universalObject.title = MetaDataManager.Title;
universalObject.contentDescription = MetaDataManager.Description;
universalObject.imageUrl = MetaDataManager.Image;
linkProperties.controlParams.Add("$desktop_url", "http://xleague.games/xleague-solitaire-share/");
linkProperties.controlParams.Add("$android_url", "http://xleague.games/android");
linkProperties.controlParams.Add("$ios_url", "https://apps.apple.com/us/app/xleague-solitaire/id1480117114");
linkProperties.controlParams.Add("$ipad_url", "https://apps.apple.com/us/app/xleague-solitaire/id1480117114");
linkProperties.controlParams.Add("$match_duration", "2000");
linkProperties.controlParams.Add("$og_title", MetaDataManager.Title);
linkProperties.controlParams.Add("$og_description", MetaDataManager.Description);
linkProperties.controlParams.Add("$og_image_url", MetaDataManager.Image);
linkProperties.controlParams.Add("$deviceID", deviceUniqueIdentifier);
Branch.getShortURL(universalObject, linkProperties, (param, error) =>
{
if (error != null)
{
Debug.LogError("Branch.getShortURL failed: " + error);
}
else if (param != null)
{
callback(param);
}
});
我可以从Unity Branch中获得以下短网址。
https:/xleague.app.linkr7DxT2wkZ5。
https:/xleague.app.link4WPwY7jm05
https:/xleague.app.linkLFfAOZuo05
https:/xleague.app.linkhVR3fr0n05。
而我使用下面的代码检索BranchUniversalObject和BranchLinkProperties。
void Start()
{
Branch.initSession(CallbackWithBranchUniversalObject);
}
void CallbackWithBranchUniversalObject(BranchUniversalObject buo, BranchLinkProperties linkProps, string error)
{
if (error != null)
Debug.Log($"Error : {error}");
else
{
Debug.Log(buo.ToJsonString());
Debug.Log(linkProps.ToJsonString());
if (linkProps.controlParams.ContainsKey("$deviceID"))
{
string senderDeviceID = linkProps.controlParams["$deviceID"];
...
}
}
}
如果我在iPhone或Android上点击共享链接,它会将我重定向到Appstore或Google Play Store。我可以在Appstore和Google Play Store上安装应用,但当我打开应用时,initSession返回空的BranchUniversalObject JSON和BranchLinkProperties JSON。
BranchUniversalObject JSON
{
"$canonical_identifier": "",
"$canonical_url": "",
"$og_title": "",
"$og_description": "",
"$og_image_url": "",
"$publicly_indexable": "0",
"$locally_indexable": "0",
"$exp_date": "69425078400000",
"$keywords": [],
"metadata": "{}"
}
BranchLinkProperties JSON
{
"~tags": [],
"~feature": "",
"~alias": "",
"~channel": "",
"~stage": "",
"~duration": "0",
"control_params": {}
}
更让我困惑的是,initSession有时会按照预期返回正确的BranchUniversalObject JSON和BranchLinkProperties JSON。我想我创建的Branch Short URL只适用于第一次点击.如果你能帮助我,我会非常感激你。