使用Swift在Notification Hub中无效的标签

时间:2015-10-30 18:42:48

标签: swift apple-push-notifications azure-notificationhub

当我将标签设置为nil时,一切都很好。但格式化标签似乎不起作用。

有什么想法吗?

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/

2 个答案:

答案 0 :(得分:2)

通过大量试验和错误,我能够创建一个解决方案。希望这有助于下一个人。首先,标签名称中没有空格。其次,Objective-C的API签名与Swift的签名不同。

这是一个有效的Swift示例:

    public List<Component> getAllComponents(Class componentClass)
    {
        List<Component> components = new ArrayList<Component>();
        for (Component c : _components)
        {           
            if (c.getClass() == componentClass)
                components.add(c);
        }

        return components;
    }

答案 1 :(得分:1)

确保您的代码有效:

  

标签可以是任何字符串,最多120个字符,包含字母数字   和以下非字母数字字符:'_','@','#','。',   ':',' - '。

请参阅https://msdn.microsoft.com/en-us/library/azure/dn530749.aspx