iOS上的Windows Azure Notification中心注册不正确地格式化标签

时间:2015-03-12 15:41:31

标签: ios swift azure azure-mobile-services

我无法使用标记向Azure Notification Hub注册我的(Swift)iOS应用程序。

根据https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx,通知中心的请求主体应如下所示:

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
    <content type="application/xml">
        <AppleRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
            <Tags>myTag, myOtherTag</Tags>
            <DeviceToken>{DeviceToken}</DeviceToken> 
        </AppleRegistrationDescription>
    </content>
</entry>

但是,在使用Azure SDK for iOs注册时,&lt; Tags&gt;元素看起来像这样:

<Tags>(myTag, myOtherTag)</Tags>

我的代码如下:

var tableArray = [String]()
.
.
.
let hub = SBNotificationHub(connectionString:delegate.notficationEndpoint, notificationHubPath:delegate.notficationHubPath)
let tags = NSSet(array:self.tableArray)   

// Register the new tags with the push server
hub.registerNativeWithDeviceToken(deviceToken, tags:tags)

2 个答案:

答案 0 :(得分:0)

我可能错了,但我觉得这很有效:

let tags: [String] = ["myTag","myOtherTag"]

或在你的情况下:

let tags: [String] = tableArray

答案 1 :(得分:0)

添加LoVo的答案:在它之上......我们需要将标记解析为NSSet而不是NSArray,因此我们需要将其转换为Set<NSObject>

let tags = ["myTag","myOtherTag"]
let tagSet = NSSet(array: tags) as  Set<NSObject>