如何解决Swift-窗口小部件无法访问应用程序组
我最近一直在尝试制作一个小部件,并希望在我的小部件和我的应用之间共享一段数据。
let starMaterial = new Three.PointsMaterial({
size: 0.7,transparent: true,map: sprite,});
上面的代码在我的应用程序上可以正常工作,但是当我在窗口小部件上运行它时,它将提供以下输出。我检查了应用程序组是否正确,并且在iOS应用程序和小部件上均处于活动状态。
static var sharedDataFileURL: URL {
let appGroupIdentifier = "group.com.unknownstudios.yk"
guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)
else { preconditionFailure("Expected a valid app group container") }
return url.appendingPathComponent("userID.plist")
}
编辑:
我也尝试过使用UserDefaults,但是它们也不起作用。
以下是我使用FileManager和UserDefaults的方式
[unspecified] container_create_or_lookup_path_for_platform: client is not entitled
[unspecified] container_create_or_lookup_app_group_path_by_app_group_identifier: client is not entitled
Fatal error: Expected a valid app group container: file WidgetExtension/Library.swift,line 143
以下是我尝试从小部件读取数据的方法:
UserDefaults(suiteName: "group.com.unknownstudios.yk")!.set("**USERID**",forKey: "userID")
let data = Data("**USERID**".utf8)
do {
try data.write(to: URL.sharedDataFileURL,options: .atomic)
} catch {
print(error.localizedDescription)
}
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。