我正在使用适用于 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");
或者,您可以通过以下方式注册模板通知:
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/