SWIFT:做我有别人设定不同的文本每一次的记录? [英] SWIFT: do I have someone set a record with different text every time?

查看:200
本文介绍了SWIFT:做我有别人设定不同的文本每一次的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我做了一个聊天室,当有人发送消息时,还添加了一个订阅我的云套件数据库,但问题是有不能有更多的则是订阅相同的名称之一,我希望他们能够设置多个订阅然后之一。下面是一些code:

So I made a chatroom and when someone sends a message they also add a Subscription in my cloud kit database but the problem is there cant be more then one of the same name that is a subscription and I want them to be able to set more subscriptions then one. Here is some code:

    func setupCloudKitSubscription () {
    let userDefaults = NSUserDefaults.standardUserDefaults()

    if userDefaults.boolForKey("subscribed") == false {
        let predicate = NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)
        let subscription = CKSubscription(recordType: "Extra1", predicate: predicate, options: CKSubscriptionOptions.FiresOnRecordCreation)

        let notificationInfo = CKNotificationInfo()
        notificationInfo.alertLocalizationKey = "New Sweet"
        notificationInfo.shouldBadge = true

        subscription.notificationInfo = notificationInfo

        let publicData = CKContainer.defaultContainer().publicCloudDatabase

        publicData.saveSubscription(subscription) { (subscription:CKSubscription?, error:NSError?) -> Void in
            if error != nil {
                print(error?.localizedDescription)
            }else{
                userDefaults.setBool(true, forKey: "subscribed")
                userDefaults.synchronize()

您看看它是如何说RECORDTYPE:Extra1我怎么能做出的Extra1不同的文本每次有人让订阅?谢谢!

You see how it says recordType: "Extra1" how can I made the "Extra1" different text every time someone makes a subscription? Thanks!

推荐答案

您的问题并不完全清楚。我想你想问的是,你要订阅送你每个通知不同的消息。

Your question is not completely clear. I think what you wanted to ask is that you want the subscription to send you a different message with each notification.

您可以将其设置为显示记录的一个或多个字段。对于这样做,你应该使用这样的:

You could set it to display one or more fields of the record. For doing that you should use something like this:

notificationInfo.alertLocalizationKey = "Response: %1$@"
notificationInfo.alertLocalizationArgs = ["responseField"]

那么你还需要这在Localization.Strings文件。

Then you also need this in your Localization.Strings file.

"Response: %1$@" = "Response: %1$@";

这篇关于SWIFT:做我有别人设定不同的文本每一次的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆