首页 > 解决方案 > 尝试向 Azure 通知中心注册设备时出错

问题描述

我有一个 xamarin 应用程序,它将通过 Azure 函数及其通知中心输出绑定发送通知。

在 xamarin 应用程序中,我有一个获取令牌并存储在缓存中的 android 服务

    [Service]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService
{
    private App _app => (App)Xamarin.Forms.Application.Current;
    private readonly ICachingService _cachingService;
    public MyFirebaseIIDService()
    {
        var xx = typeof(ICachingService);
        _cachingService = (CachingService)App.Instance.Container.Resolve(xx);

    }
    public override void OnTokenRefresh()
    {

            var refreshedToken = FirebaseInstanceId.Instance.Token;
            _cachingService.FireBaseToken = refreshedToken;
            Console.WriteLine($"Token received: {refreshedToken}");
       //     SendRegistrationToServerAsync(refreshedToken);

    }

}

用户登录后,我想使用其 ID 作为标签,并调用另一个尝试使用此标签注册设备的 android 服务

  var client = new MobileServiceClient(App.MobileServiceUrl);
            var push = client.GetPush();
            var reg = new Registration(token, tags);
            await push.RegisterAsync(reg);

此时我有包含 userId 的令牌和标签列表,因为稍后我希望该用户仅获得仅适用于他们的通知。

在 push.RegisterAsyn 方法上我得到一个错误。

您要查找的资源已被删除、名称已更改或暂时不可用。

请注意,App.MobileServiceUrl 是连接到通知中心的 Azure 移动应用的 url

在此处输入图像描述

除此之外,这个 Azure 移动应用程序只有默认的 TODO 控制器和模板附带的所有内容。我的发送通知代码将在使用通知中心输出绑定的天蓝色函数中。

我还更新了所有与 azure 相关的 nugets,它尝试点击此 url 进行注册。 https://xxxx.azurewebsites.net/push/registrations?deviceId=dTd4wba1KTU:APA91bHKOZRX9LFzEGD-yqyz4p-whqh6UsoEAlgpFHfBxu00MhLo-------yyyyyyyyyyyyyyyyeuoRmH4h9czeQbvGRgbwt4zMlrvRIlvLDZ-kTu_Dcu2iHx9I5u0gheQQ3Z2tYq66O&platform=gcm

标签: azurexamarinazure-notificationhub

解决方案


我使用了错误的nuget。我不得不使用

Microsoft.Azure.Mobile.Client

相反,我使用的是 Azure 移动服务 nuget。

两者都有 MobileServiceClient 类,这就是我感到困惑的原因。现在我没有得到例外。


推荐阅读