gpt4 book ai didi

objective-c - 配套应用和应用扩展之间的应用组中的值并不总是存在

转载 作者:太空狗 更新时间:2023-10-30 03:09:02 26 4
gpt4 key购买 nike

有时,但并非总是如此(我已经让这个工作了一段时间),应用程序/扩展程序处于一种状态,我无法读取我的应用程序组中我的配套应用程序和我的应用程序之间设置的标志延期。不知道它是如何进入这种状态的,也不知道为什么值不同,但它关键对我的应用程序来说,它们始终保持同步。

配套应用 viewDidLoad:

NSUserDefaults *myAppSettings = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp"];

.....

[myAppSettings setBool:true forKey:@"myBool"];

[myAppSettings synchronize];

NSLog([myAppSettings boolForKey:@"myBool"] ? @"Companion app - bool TRUE" : @"Companion app - bool FALSE");

应用扩展viewDidLoad

NSUserDefaults *myAppSettings = [[NSUserDefaults alloc] initWithSuiteName:@"group.myapp"];

[myAppSettings synchronize];

NSLog([myAppSettings boolForKey:@"myBool"] ? @"App extension app - bool TRUE" : @"App extension - bool FALSE");

控制台输出

Companion app - bool TRUE
App extension - bool FALSE

我也在我的配套应用程序进入后台之前同步。我在门户等中设置了我的应用程序组。

我做错了什么?

编辑

显然其他人也有这个问题: https://devforums.apple.com/message/977151#977151

"I think that this is currently very glitchy.

Sometimes the data sharing works, then a change and all of a sudden the widget can't see the shared data anymore (both on Simulator and device).

Annoying and hope it's a bit more reliable in next beta!"

编辑 2看起来另一个人也报告了这个确切的问题:

"I also noticed the same thing too.This not only happen to the NSUserDefaults, but also all the files in the container folder. The keyboard extension suddenly will lose read/write pemission to the container folder after using the keyboard for a while."

编辑 3更多证据:https://devforums.apple.com/message/1028078#1028078

After I upgrade to beta 3, I noticed that sometimes the keyboard failed to open the database because it failed to access to the DB file. The keyboard has been able to access to the file before.

enter image description here enter image description here

编辑 4

看起来这可能是因为键盘丢失了 RequestsOpenAccess 标志。但我无法重现它,我也无法确定。

编辑 5

似乎其他人在 iOS8 GM 构建中报告了这一点:

This issue still persists for me in the GM. It seems related to a keyboard crash.. but also there seems to be some contention between keyboard and containing app in terms of who creates the suite in what order. I think this problem is on Apple's end. Trust me, I WANT it to be my fault but I've spent countless hours with trial and error. No matter what I do in code and verify with NSLog, it will end up in this state eventually. Hoping someone finds a magic pill. :S

有人解决了吗?

最佳答案

必须请求开放访问权限才能访问共享的NSUserDefaults。它直接在 App Extension Programming guide 中说明:

默认情况下,键盘没有网络访问权限,也无法与其包含的应用程序共享容器。要启用这些功能,请将 Info.plist 文件中的 RequestsOpenAccess bool 键的值设置为 YES。

确保将 RequestsOpenAccess 字段更改为 YES。您会在键盘的 Info.plist > NSExtension > NSExtensionAttributes > RequestOpenAccess 中找到它。然后在设置里去掉键盘,删除app,重新运行,重新添加键盘。添加后,点击键盘名称,然后翻转开关以启用允许完全访问。您需要指示用户按照相同的步骤授予访问权限(并向他们保证您不是坏人),否则它根本无法工作,您将永远无法获得存储在共享容器中的数据。请注意,在 iOS 8.3+ 中,如果用户未启用完全访问权限,键盘将能够访问共享容器,但出于安全和隐私目的,写入它不会保存数据。在 8.2 中,您无法在未授予开放访问权的情况下访问该数据。

关于objective-c - 配套应用和应用扩展之间的应用组中的值并不总是存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25186025/

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