Azure移动服务未在Android上注册推送通知标签 [英] Azure mobile service doesn't register push notifications tags on Android

查看:88
本文介绍了Azure移动服务未在Android上注册推送通知标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码向带有标签的特定用户发送推送通知(使用Azure移动服务的VS Cordova Project).

I'm trying to use the following code to send push notifications to specific users with tags (VS Cordova Project using Azure mobile service).

            var tags = [userid, platform];
            // Get the handle returned during registration. 
            var handle = data.registrationId;
            // Set the device-specific message template. 
            if (platform == "android" || platform == "Android") {
                // Template registration. 
                var template = '{ "data" : {"message":"$(message)"}}';
                // Register for notifications. 
                mobileServiceClient.push.gcm.registerTemplate(handle,
                    "myTemplate", template, null, tags)
                    .done(registrationSuccess, registrationFailure);
            } else if (platform == "iOS") {

                // Template registration. 
                var template = '{"aps": {"alert": "$(message)"}}';

                // Register for notifications.             
                mobileServiceClient.push.apns.registerTemplate(handle,
                    "myTemplate", template, null, tags)
                    .done(registrationSuccess, registrationFailure);
            }

它已成功使用Apple APNS的标签注册,但是在android上,它仅注册了设备,但未注册标签.

It registered successfully with the tags for Apple APNS , however on android it only registered the device, but the tags doesn't get registered.

我正在使用推插件1.4.4和Azure移动服务1.2.9

I'm using push plugin 1.4.4 and Azure mobile service 1.2.9

有人知道如何解决此问题吗?任何建议表示赞赏,谢谢!

Does anyone knows how to fix this? Any suggestion is appreciated, thanks!

推荐答案

我的博客

My blog here details on how to receive notifications based on tags in a Cordova client. Basically you'll need a bit of server side code to update your installation / registration to handle specific tags. That's this bit of code:

NotificationHubClient _hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName);

public async Task CreateOrUpdateInstallationAsync(string installationId, string registrationId, IEnumerable<string> tags)
{
    Installation installation = new Installation();
    installation.InstallationId = installationId;
    installation.PushChannel = registrationId;
    installation.Tags = tags.ToArray();
    installation.Platform = NotificationPlatform.Gcm;

    await _hub.CreateOrUpdateInstallationAsync(installation);
}

这篇关于Azure移动服务未在Android上注册推送通知标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆