Man*_*n S 5 push-notification ios swift unnotificationserviceextension
在我的场景中,我在父 iOS 应用程序和通知服务扩展之间共享数据。我使用的是 Xcode 10.2.1,iOS 部署目标 10.0
我们已经尝试了 NSUserDefaults 和 Keychain 组,它按预期工作。将值(存储模型或数据类型)从通知服务扩展(TargetB)保存到 MainApp(TargetA)的任何其他方式。
一旦应用程序处于终止状态,我们就将值附加到模型中,并将其保存在钥匙串中。
保存到 Keycahin:
NotificationAPI.shared.NotificationInstance.append(Notifications(title: messageTitle, message: messageBody,date: Date()))
let notification = NotificationAPI.shared.NotificationInstance
let value = keychain.set(try! PropertyListEncoder().encode(notification), forKey: "Notification")
Run Code Online (Sandbox Code Playgroud)
对于用户默认:
var defaults = NSUserDefaults(suiteName: "group.yourappgroup.example")
Run Code Online (Sandbox Code Playgroud)
当应用程序处于非活动状态时,我想将数据从目标 B 传输到目标 A?另一个传输或保存数据?请帮我?
| 归档时间: |
|
| 查看次数: |
2867 次 |
| 最近记录: |