ios - Azure 通知中心不适用于 ios

标签 ios azure xamarin push-notification apple-push-notifications

Following this tutorial我创建了 azure 通知中心并添加到我的应用程序注册中。我的应用程序注册远程通知成功,当我尝试在后端注册设备时,我成功获得了我的安装 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);
}

但是当尝试发送通知时

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

结果显示“发送成功:0,发送失败:0。

造成这个问题的原因是什么?

更新

我不认为证书或配置文件有问题,因为当我尝试通过 azure 发送通知时 - 它会发送。 (虽然我没有收到,但这已经是另一个问题了)。 enter image description here

更新2

我也尝试发送到已注册的标签,

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

和苹果原生通知,但结果是一样的。

hub.SendAppleNativeNotificationAsync(payload);

顺便说一句,notificationId 为空,状态通知显示为“已入队”。

最佳答案

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

关于ios - Azure 通知中心不适用于 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36956993/

相关文章:

c# - 如何限制 MonoTouch 中的 UITextView 字符限制?

ios - 有没有办法以编程方式获取 iOS 上第 3 方应用程序的 UI 层次结构?

ios - UITableViewCell 背景颜色与我输入的不同

c# - 如何从旧的 asp.net 成员资格创建用户到新的 MVC .net 并发送密码重置

c# - 有没有办法模拟Azure CloudQueueClient或CloudQueue?

c# - 具有绑定(bind)属性的图像 IsEnabled 不起作用 Xamarin 表单

ios - 如果我创建个人帐户而不是公司帐户,是否可以让多个开发人员测试我的 iPhone/iPad 应用程序?

ios - 扫描后(或使用键盘后)从手动输入中删除 CVV

azure - Docker : how to read configmap & secret in asp. 网络核心应用程序?

android - 让 MvxAutoCompleteTextView 工作