3

我使用的Windows Azure的iOS模板通過Azure的服務總線通知集線器IOS通知

服務總線通知集線器我用下面的代碼註冊設備:

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

      } 


     }]; 

,並從淨後端發送通知通過使用下面的代碼:

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

感謝

回答

4

您註冊本地通知,但隨後你發送通知範本。 如果你想發送本地(這將需要額外的發送,如果你想達到在不同的平臺設備),你必須使用

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

+0

感謝埃利奧 運行這一行: hub.SendAppleNativeNotification(「{\」戒備\「:\」這是我的警告消息對於iOS!\「}」,「tag」); 我得到這個錯誤: 遠程服務器返回一個錯誤:(400)錯誤的請求。提供的通知負載無效.TrackingId:3d8e3198-223b-4245-ad2f-aebd4a59e4ae_G7,TimeStamp:2013年7月10日上午2:51:46 –

+0

對不起,警報屬性必須位於https中所示的「aps」元素內://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html Eg {「aps」:{「alert」:「你好 !」}} –

+0

偉大的埃利奧感謝;-) –

相關問題