gpt4 book ai didi

swift - 标签在 Swift 的通知中心不工作

转载 作者:搜寻专家 更新时间:2023-11-01 06:43:17 26 4
gpt4 key购买 nike

当我将标签设置为 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/

最佳答案

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

这是一个有效的 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);
}
}
}
}

关于swift - 标签在 Swift 的通知中心不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33442880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com