2015-10-30 23 views
1

當我將標籤設置爲零時,它的效果都很好。但格式化標籤似乎不起作用。標籤在Swift中無法在通知中心工作

任何想法?

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 

    if Leagues.count > 0 { 
     var myLeague: [String] = [String]() 
     for eachleague in Leagues { 
      myLeague.append(eachleague.LeagueName) 
     } 


     let categories: NSSet = NSSet(array: myLeague) 

     let hub : SBNotificationHub = SBNotificationHub(connectionString: "Endpoint=<my endpoint>", notificationHubPath: "<myhub>") 

     hub.registerNativeWithDeviceToken(deviceToken, tags: categories as! Set<NSObject>) { (error) -> Void in 
      if (error != nil){ 
       print("Error registering for notifications: %@", error); 
      } 
     } 
    } 
} 

我試圖按照在Objective-C這個例子:https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-ios-send-breaking-news/

+0

我不知道如果我找到解決辦法 - 但我也認識到,在他們的空間標籤似乎被阻塞。可能是這裏的問題。 – Davemen

回答

2

通過大量的試驗和錯誤,我能夠創建一個解決方案。希望這有助於下一個人。首先,標籤名稱中沒有空格。其次,Objective-C的API簽名與Swift不同。

這裏的工作斯威夫特例如:

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 

    if Leagues.count > 0 { 
     var myLeague: [AnyObject] = [AnyObject]() 
     for eachleague in Leagues { 
      myLeague.insert(eachleague.LeagueID, atIndex: 0) 
     } 

     let tagSet: NSSet = NSSet(array: myLeague) 

     let hub : SBNotificationHub = SBNotificationHub(connectionString: gEndPointName, notificationHubPath: gHubName) 

     hub.registerNativeWithDeviceToken(deviceToken, tags: tagSet as! Set<NSObject>) { (error) -> Void in 
      if (error != nil){ 
       print("Error registering for notifications: %@", error); 
      } 
     } 
    } 
}