Azure Service Bus通知中心的ios通知模板(Template for ios notification by Azure Service Bus Notification Hubs)

编程入门 行业动态 更新时间:2024-10-26 08:26:47
Azure Service Bus通知中心的ios通知模板(Template for ios notification by Azure Service Bus Notification Hubs)

我正在为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 Backend发送通知:

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

谢谢

i am using windows azure Service Bus Notification Hubs for ios

i register my device by following code :

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

and sending Notification from .Net Backend by using following code :

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

i able to receive notification but my problem is : notification does not have any property that i added , no sound , no badge ...

if you can please help me

references : http://msdn.microsoft.com/en-US/library/jj927168.aspx

thanks

最满意答案

您注册了本机通知,但之后您正在发送模板通知。 如果您想发送本机(如果您想要访问不同平台上的设备,则需要额外的发送),您必须使用

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

有关iOS有效内容格式,请参阅https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html 。

或者,您可以注册模板通知:

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

You registered for native notifications but then you are sending a template notification. If you want to send native (this will require additional sends if you want to reach devices on different platforms) you have to use

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

Please refer to https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html for the iOS payload format.

Alternatively, you can register for template notifications with:

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

Using a template like:

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

Then you can send notifications using hub.SendTemplateNotification like you are already doing.

For more information regarding the difference between template and native please refer to: http://msdn.microsoft.com/en-us/library/jj927170.aspx

更多推荐

本文发布于:2023-07-28 16:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1306841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   模板   中心   Azure   Service

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!