Azure mobile service doesn't register push notifications tags on Android

倾然丶 夕夏残阳落幕 提交于 2019-12-12 02:25:28

问题


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);
            }

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

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!


回答1:


After tracing the source code of azure mobile service plugin, I found that

gcm.prototype.registerTemplate = function (deviceId, name, bodyTemplate, tags) 

is missing the "expiryTemplate" parameter. Changing it to

gcm.prototype.registerTemplate = function (deviceId, name, bodyTemplate, expiryTemplate, tags) 

fix the problem.




回答2:


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);
}


来源:https://stackoverflow.com/questions/33883726/azure-mobile-service-doesnt-register-push-notifications-tags-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!