Unity: 在 DynamicLinkReceived 回调事件中接收 Firebase Short DynamicLink
Unity: Receive Firebase Short Dynamic Link in DynamicLinkReceived callback event
我想为 Unity (Android/iOS) 使用 Firebase Dynamic Links,这样用户就可以邀请朋友并获得奖励。
每个用户都以 https://test.page.link/abcd 的形式获得不同的短动态 Link
用户可以分享这个短动态Link给朋友
当受邀好友进入应用时,会调用此回调。
private void OnDynamicLink(object sender, EventArgs args) {
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}",
dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
不幸的是,我只取回了创建短动态 link.[=17 所必需的基础 link =]
Received dynamic link https://www.example.com/referral?xxxxxxxxxx
我在我的 iOS 应用程序中获得了额外的本机输出:
IOSNative::Native->Unity callback data:
{"m_EventName":"continueUserActivity","m_Data":"https://test.page.link/?link=https://www.example.com/referral?xxxxxxxxxx&apn=de.test.testapp&isi=123456789&ibi=de.test.testapp&cid=1579347010984123886&_osl=https://test.page.link/abcd&_fpb=AB6327276CFGHT==&_cpt=cpit&_iumenbl=1&_iumchkactval=1&_plt=2076&_uit=2692&_cpb=1"}
2020-01-14 15:30:20.455009+0100 ambassador[315:8406]
IOSNative::Native->Unity callback data:
{"m_EventName":"applicationDidBecomeActive","m_Data":""}
现在我的问题是如何获取我在 OnDynamicLink 回调中与朋友分享的生成的短动态 link(https://test.page.link/abcd)?
我需要附加本机输出中看到的参数“&_osl”后面的值。但我在 Unity (https://www.example.com/referral?xxxxxxxxxx) 中只得到了 Base Url。
我最后的解决方案是在 DynamicLinks.GetShortLinkAsync 的帮助下缩短 BaseLink。
//unescape url
baseLink = UnityEngine.Networking.UnityWebRequest.UnEscapeURL(baseLink);
var components = new DynamicLinkComponents(
// The base Link.
new Uri(baseLink),
// The dynamic link URI prefix.
domainUriPrefix) {
IOSParameters = new IOSParameters(PackageName) {
AppStoreId = "XXXXXXXXX"
},
AndroidParameters = new AndroidParameters(PackeName)
};
string inviteLink = string.Empty;
await DynamicLinks.GetShortLinkAsync(components, options).ContinueWith((task) => {
if (task.IsCanceled) {
Debug.LogError("GetShortLinkAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("GetShortLinkAsync encountered an error: " + task.Exception);
return;
}
// Short Link has been created.
inviteLink = task.Result.Url.ToString();
});
我想为 Unity (Android/iOS) 使用 Firebase Dynamic Links,这样用户就可以邀请朋友并获得奖励。 每个用户都以 https://test.page.link/abcd 的形式获得不同的短动态 Link 用户可以分享这个短动态Link给朋友
当受邀好友进入应用时,会调用此回调。
private void OnDynamicLink(object sender, EventArgs args) {
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}",
dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
不幸的是,我只取回了创建短动态 link.[=17 所必需的基础 link =]
Received dynamic link https://www.example.com/referral?xxxxxxxxxx
我在我的 iOS 应用程序中获得了额外的本机输出:
IOSNative::Native->Unity callback data: {"m_EventName":"continueUserActivity","m_Data":"https://test.page.link/?link=https://www.example.com/referral?xxxxxxxxxx&apn=de.test.testapp&isi=123456789&ibi=de.test.testapp&cid=1579347010984123886&_osl=https://test.page.link/abcd&_fpb=AB6327276CFGHT==&_cpt=cpit&_iumenbl=1&_iumchkactval=1&_plt=2076&_uit=2692&_cpb=1"} 2020-01-14 15:30:20.455009+0100 ambassador[315:8406] IOSNative::Native->Unity callback data: {"m_EventName":"applicationDidBecomeActive","m_Data":""}
现在我的问题是如何获取我在 OnDynamicLink 回调中与朋友分享的生成的短动态 link(https://test.page.link/abcd)?
我需要附加本机输出中看到的参数“&_osl”后面的值。但我在 Unity (https://www.example.com/referral?xxxxxxxxxx) 中只得到了 Base Url。
我最后的解决方案是在 DynamicLinks.GetShortLinkAsync 的帮助下缩短 BaseLink。
//unescape url
baseLink = UnityEngine.Networking.UnityWebRequest.UnEscapeURL(baseLink);
var components = new DynamicLinkComponents(
// The base Link.
new Uri(baseLink),
// The dynamic link URI prefix.
domainUriPrefix) {
IOSParameters = new IOSParameters(PackageName) {
AppStoreId = "XXXXXXXXX"
},
AndroidParameters = new AndroidParameters(PackeName)
};
string inviteLink = string.Empty;
await DynamicLinks.GetShortLinkAsync(components, options).ContinueWith((task) => {
if (task.IsCanceled) {
Debug.LogError("GetShortLinkAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("GetShortLinkAsync encountered an error: " + task.Exception);
return;
}
// Short Link has been created.
inviteLink = task.Result.Url.ToString();
});