azure - Azure 服务总线通知中心的 ios 通知模板

标签 azure notifications apple-push-notifications azureservicebus

我正在使用适用于 ios 的 Windows azure 服务总线通知中心

我通过以下代码注册我的设备:

SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:
                                  @"Endpoint=sb://......" notificationHubPath:@"...."];


        NSMutableSet *set = [NSMutableSet set];
        [set addObject:@"general"];
        [hub registerNativeWithDeviceToken:deviceToken tags:[set copy] completion:^(NSError* error) {
            if (error != nil) {
                NSLog(@"Error registering for notifications: %@", error);
                [self.delegate homePopUpViewControllerEnterButtonPress:self];

            }


        }];

并使用以下代码从.Net后端发送通知:

var hubClient = NotificationHubClient.CreateClientFromConnectionString(<connection string>, "<notification hub name>");

IDictionary<string, string> properties = new Dictionary<string, string>();

properties.Add("badge", "1");
properties.Add("alert", "This is Test Text");
properties.Add("sound", "bingbong.aiff");

hubClient.SendTemplateNotification(properties,  "general");

我能够接收通知,但我的问题是:通知没有我添加的任何属性,没有声音,没有徽章...

如果可以请帮帮我

引用文献:http://msdn.microsoft.com/en-US/library/jj927168.aspx

谢谢

最佳答案

您注册了 native 通知,但随后您正在发送模板通知。 如果您想发送 native (如果您想到达不同平台上的设备,这将需要额外的发送),您必须使用

hub.SendAppleNativeNotification(
    "{ \"aps\": { \"alert\": \"This is my alert message for iOS!\"}}", "tag");

请引用https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html iOS 负载格式。

或者,您可以通过以下方式注册模板通知:

NSString* template = @"{aps: {alert: \"$(myToastProperty)\"}}";
[hub registerTemplateWithDeviceToken:deviceToken 
                                name:@"myToastRegistration"
                    jsonBodyTemplate:template
                      expiryTemplate:nil
                                tags:nil 
                          completion:^(NSError* error) {
    if (error != nil) {
        NSLog(@"Error registering for notifications: %@", error);
    }
}];

使用如下模板:

{
   “aps”: {
       “alert”: “$(alert)”
   }
}

然后您可以像您已经在做的那样使用 hub.SendTemplateNotification 发送通知。

更多关于模板和原生的区别请引用:http://msdn.microsoft.com/en-us/library/jj927170.aspx

关于azure - Azure 服务总线通知中心的 ios 通知模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17480326/

相关文章:

azure - Azure 上的 SignalR 聊天

angularjs - 获取 JSON 格式的 Azure Blob 数据

android - BroadcastReceiver 中 onReceive 方法中关于 Intent null 的附加信息

apple-push-notifications - 使用 php 的 APNs 提供商 API HTTP/2,curl 导致发送的多个推送通知出现错误

ios - 当应用程序终止时,APN 在委托(delegate)中接收通知数据

c# - Azure Function 中的自定义绑定(bind)未得到解决

ios - Firebase 通知未显示 IOS,但消息显示在控制台上

javascript - 如何将material-ui Snackbar实现为全局函数?

ios - 如何从推送通知响应 Swift 3/iOS 获取数据

sql-server - 本地 SQL Server 数据库和 Azure SQL 数据库之间的两种方式同步