gpt4 book ai didi

c# - 如何处理firebase短动态链接成功结果

转载 作者:太空宇宙 更新时间:2023-11-03 22:42:32 25 4
gpt4 key购买 nike

我在 Xamarin Android 中有创建 firebase shortdynamic 链接的方法:

private void GetDynamicLink()
{

string uid = "My_Id";
string link = "https://ledrop.com/?invitedby=" + uid;
var task = FirebaseDynamicLinks.Instance.CreateDynamicLink()
.SetLink(Android.Net.Uri.Parse(link))
.SetDynamicLinkDomain("ledrop.page.link")
.SetAndroidParameters(
new DynamicLink.AndroidParameters.Builder(PackageName)
.SetMinimumVersion(125)
.Build()).BuildShortDynamicLink().AddOnSuccessListener(this, new dynamicLinkListener());


}

我附加了一个 onsuccess 监听器,如上所示,然后我像这样处理监听器:

internal class dynamicLinkListener : Java.Lang.Object, IOnSuccessListener, IOnFailureListener
{


public void OnFailure(Java.Lang.Exception e)
{
Console.WriteLine(e.Message);
}

void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
{

var sDynamicLink = result as IShortDynamicLink;

}

}

但是 sDynamicLink 变量返回 null,我如何从结果中获取 shortLink?

最佳答案

像这样使用 JavaCast

class OnSuccessListner : Java.Lang.Object, IOnSuccessListener
{
TaskCompletionSource<string> _tcs;

public OnSuccessListner(TaskCompletionSource<string> tcs)
{
_tcs = tcs;
}

void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
{
var link = result.JavaCast<IShortDynamicLink>();
_tcs.TrySetResult(link.ShortLink.ToString());
}
}

关于c# - 如何处理firebase短动态链接成功结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51543194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com