简体   繁体   English

Azure通知中心不适用于ios

[英]Azure Notification Hub doesn't work for ios

Following this tutorial I created azure notification hub and added to my app registation. 在本教程之后,我创建了azure通知中心并添加到我的app注册中。 My app register for remote notification successful and when I tried to get registered device on back end, I successful got my installation id. 我的应用程序注册远程通知成功,当我试图在后端获得注册设备时,我成功获得了我的安装ID。

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
MobileServiceClient client = QSTodoService.DefaultService.GetClient;

const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(messageParam)\"}}";

JObject templates = new JObject();
templates["genericMessage"] = new JObject
{
    {"body", templateBodyAPNS}
};

// Register for push with your mobile app
var push = client.GetPush();
push.RegisterAsync(deviceToken, templates);
}

But when try to send notification 但是当试图发送通知时

        // Get the settings for the server project.
        HttpConfiguration config = this.Configuration;
        MobileAppSettingsDictionary settings =
            this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings();

        // Get the Notification Hubs credentials for the Mobile App.
        string notificationHubName = settings.NotificationHubName;
        string notificationHubConnection = settings
            .Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString;

        // Create a new Notification Hub client.
        NotificationHubClient hub = NotificationHubClient
        .CreateClientFromConnectionString(notificationHubConnection, notificationHubName);

        // Sending the message so that all template registrations that contain "messageParam"
        // will receive the notifications. This includes APNS, GCM, WNS, and MPNS template registrations.
        Dictionary<string, string> templateParams = new Dictionary<string, string>();
        templateParams["messageParam"] = "some message";

        try
        {
            var result = hub.SendTemplateNotificationAsync(templateParams);
        }
        catch (System.Exception ex)
        {
            config.Services.GetTraceWriter()
                .Error(ex.Message, null, "Push.SendAsync Error");
        }

Result said "successful sent: 0, failed sent: 0. 结果说“成功发送:0,发送失败:0。

What can be the reason of this trouble? 这种麻烦的原因是什么?

Update 更新

I don't think the problem with sertificate or provisioning profile as when I'm trying to send notification via azure - it send. 当我尝试通过azure发送通知时,我不认为sertificate或配置文件的问题 - 它发送。 (though I don't receive, but it's already another problem). (虽然我没有收到,但这已经是另一个问题)。 在此输入图像描述

Update 2 更新2

I've also tried to send to registered tag, 我也尝试发送到注册标签,

string payload = "{\"aps\":{\"alert\":\"Notification Hub test notification\"}}";
List<string> tags = new List<string> {"testTag"};
hub.CreateAppleTemplateRegistrationAsync(token,payload,tags);

Dictionary<string, string> templateParams = new Dictionary<string, string>();
            templateParams["messageParam"] = "message";
var res = hub.SendTemplateNotificationAsync(templateParams, tags);

and apple native notification, but result was the same. 和苹果原生通知,但结果是一样的。

hub.SendAppleNativeNotificationAsync(payload);

BTW, notificationId is empty and state notification shows as 'Enqueued'. BTW,notificationId为空,状态通知显示为“已排队”。

我最终从头开始学习教程,重新创建证书,配置文件,通知中心等,现在它可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM