gpt4 book ai didi

ios - CloudKit 通知

转载 作者:可可西里 更新时间:2023-11-01 03:29:03 39 4
gpt4 key购买 nike

我可能在这里遗漏了一些明显的东西。

如何创建一个 CloudKit 通知,其中包含有关您收到通知的 CKRecord 的详细信息? (即不仅仅是通用的“新项目已创建!”而是带有记录标题的通知,例如“Jill 和 Jessica 的生日派对!”)

正确的方法是为每个新记录更改创建一个带有新 notification.alertBody 的新订阅吗?这没有任何意义。

留下选项 queryNotification.recordID 将数据从 CloudKit(或我的本地存储)中拉出并以某种方式将其添加到通知中?添加或更改已通知通知的值的方法是什么?我错过了什么?

更新:根据 Edwin 的建议,这里有一个代码片段,但它不起作用。

let notification = CKNotificationInfo()
notification.alertBody = "Added: %@" as NSString
notification.alertLocalizationArgs = ["name"]

最佳答案

只需填写 CKNotificationInfo 对象的 .alertLocalizationArgs

.alertLocalizationArgs 的文档说:

Use of this property is optional. This property contains an array of NSString objects, each of which corresponds to a field of the record that triggered the push notification. Those names are used to retrieve the corresponding values from the record. The values are then used to replace any substitution variables in either the alertBody or alertLocalizationKey strings. The values themselves must be NSString, NSNumber, or NSDate objects. Do not specify keys with other values. String values that are greater than 100 characters in length may be truncated when added to the push notification.

If you use %@ for your substitution variables, those variables are replaced by walking the array in order. If you use variables of the form %n$@, where n is an integer, n represents the index (starting at 1) of the item in the array to use. Thus, the first item in the array replaces the variable %1$@, the second item replaces the variable %2$@, and so on. You can use indexed substitution variables to change the order of items in the resulting string, which might be necessary when you localize your app’s messages.

以下是我如何使用它的 2 个示例:

            notificationInfo.alertBody = "%1$@ : %2$@"
notificationInfo.alertLocalizationArgs = ["FromName", "Text"]

第二个样本:

            notificationInfo.alertLocalizationKey = "News: %1$@"
notificationInfo.alertLocalizationArgs = ["Subject"]

在 Localizable.strings 文件中,您将“News: %1$@”作为键

更新:看起来您现在需要使用 .alertLocalizationKey。所以第一个样本不再起作用。

关于ios - CloudKit 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27371588/

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