简体   繁体   English

WatchKit扩展程序没有看到针对App Group的NSUserDefaults的更新

[英]WatchKit extension doesn't see updates to NSUserDefaults for App Group

I've seen a couple of questions on this, and tried all the answers provided, and this still isn't working for me. 我已经看到了几个问题,并尝试了所提供的所有答案,但这仍然不适合我。

I'm trying to share several small pieces of data (Strings and BOOLs) between my iPhone App and its WatchKit extension. 我正在尝试在我的iPhone App和WatchKit扩展之间共享几个小块数据(字符串和BOOL)。 (If it makes any difference, the info is being read by the GlanceController of the WK app) (如果它有任何区别,WK应用程序的GlanceController正在读取信息)

Via the Developer site I created an App group (group.com.theYawns.Sorcerers-Apprentice). 通过开发者网站,我创建了一个App组(group.com.theYawns.Sorcerers-Apprentice)。 If I look at 'App IDs' there I appear to have two identical IDs for my app (com.theYawns.Sorcerers-Apprentice) plus one for the extension (com.theYawns.Sorcerers-Apprentice.watchkitextension). 如果我查看“App ID”,我的应用程序似乎有两个相同的ID(com.theYawns.Sorcerers-Apprentice)加上一个用于扩展名(com.theYawns.Sorcerers-Apprentice.watchkitextension)。 Each of these has 'App Group' enabled (for both Development and Distribution) and the app group is selected if I edit the App ID. 其中每个都启用了“应用程序组”(用于开发和分发),如果我编辑应用程序ID,则选择应用程序组。

I've turned on 'App Groups' in capabilities for both the App and the Extension. 我已经为应用程序和扩展程序启用了“应用程序组”功能。 A concern I have it that periodically -- several times a day but not every build -- if I go in and look at the Capabilities tab, I have a red exclamation point saying 'Add the App Groups' entitlement to your entitlements file. 我有一个问题,我定期 - 一天几次,但不是每次构建 - 如果我进入并查看功能选项卡,我有一个红色感叹号说'添加应用程序组'权利到您的权利文件。 If I look at the entitlements file, the entitlement is there, and if I click 'Fix issue', the red exclamation point changes to a checkmark. 如果我查看权利文件,则授权存在,如果单击“修复问题”,红色感叹号将变为复选标记。 But the fact this needs to be done multiple times per day concerns me that something is amiss. 但事实上,每天需要多次这样做,这让我觉得有些不对劲。

I've refreshed my provisioning profiles under XCode preferences many times, and while I don't see an App Groups icon under entitlements, if I hover I do see app groups in the tooltip that pops up. 我已多次在XCode首选项下刷新我的配置文件,虽然我没有在权利下看到应用程序组图标,但如果我悬停,我会看到弹出工具提示中的应用程序组。

In both my app and extension, I get a reference to the user defaults via 在我的应用和扩展程序中,我获得了用户默认值的引用

NSUserDefaults *sharedAppDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.theYawns.Sorcerers-Apprentice"]; 

I've also tried adding a [sharedAppDefaults synchonize] after each write and before my WatchKit attempts to read, just in case things weren't being flushed out. 我还尝试在每次写入之后和WatchKit尝试读取之前添加[sharedAppDefaults synchonize] ,以防万一没有被刷新。 (Didn't make any difference). (没有任何区别)。

My WatchKit extension bundle id is different from my iPhone App bundle id, which is one of the answers I saw on a different thread. 我的WatchKit扩展包ID与我的iPhone App包ID不同,这是我在不同线程上看到的答案之一。

I've also added an NSTimer to refresh the glance every 10 seconds, so if there was a timing issue with picking up the changes, I would expect it to resolve itself after an update cycle or two, but it does not. 我还添加了一个NSTimer来每10秒刷新一次,所以如果发现更改的时间问题,我希望它能在一两个更新周期后自行解决,但事实并非如此。

Really stumped ... seems others have had their issue resolved by answers from the other threads but none have worked for me. 真的很难......似乎其他人已经通过其他线程的答案解决了他们的问题,但没有一个对我有用。

Other threads I've searched include: 我搜索过的其他主题包括:

Why won't app groups work inside my WatchKit extension? 为什么我的WatchKit扩展程序中的应用程序组不起作用?

https://stackoverflow.com/questions/27047455/how-to-shared-storage-between-app-and-extension-with-app-group-and- https://stackoverflow.com/questions/27047455/how-to-shared-storage-between-app-and-extension-with-app-group-and-

WatchKit NSUserDefaults and NSKeyedUnarchiver issue WatchKit NSUserDefaults和NSKeyedUnarchiver问题

OK, I found an answer in the Apple developer forums. 好的,我在Apple开发者论坛中找到了答案。

It appeared, from the XCode target 'Capabilities' tab, that I had all the correct entitlements set. 从XCode目标“功能”选项卡中可以看出,我已经设置了所有正确的权利。 And I could see the 'Entitlements' file in my project, open it, and see that it was set up correctly. 我可以在项目中看到'Entitlements'文件,打开它,看看它是否设置正确。

BUT -- if I looked under my App Target's 'Build Settings' tab, in the 'Code Signing' section, there was no entitlements file shown. 但是 - 如果我查看App Target的“构建设置”选项卡下的“代码签名”部分,则没有显示授权文件。 (It all shows up correctly for the WatchKit Extension but not for the main iPhone app). (它全部显示在WatchKit扩展中,但不适用于主iPhone应用程序)。

When I plugged in the name of my entitlements file under Code Signing, everything started to work. 当我在Code Signing下插入我的权利文件的名称时,一切都开始起作用了。

This seems like a bug to me -- I don't believe the 'Capabilities' tab and the 'Build Settings' tab of the same target should ever be looking in different places for entitlements. 这对我来说似乎是一个错误 - 我不相信同一目标的“功能”选项卡和“构建设置”选项卡应该在不同的地方寻找权利。 But wanted to post the answer that worked for me here in case anyone else runs into this. 但是想发布一个对我有用的答案,万一其他人遇到这个问题。

Summary: to make sure entitlements are correct, you have to see the switches set properly in Capabilities, AND you have to see the entitlements file referenced under Build Settings / Code Signing. 简介:要确保权限正确,您必须在功能中正确设置开关,并且必须在Build Settings / Code Signing下查看引用的权利文件。

You have to add the entitlement to your provisioning profile of app extension.To do this, Login to your developer account to add the entitlements, after this download the latest provisioning profile. 您必须将权利添加到应用扩展程序的配置文件中。要执行此操作,请在下载最新的配置文件后登录到您的开发者帐户以添加权利。 To verify whether the app group has been enabled or not , open the downloaded provisioning profile in "TextEditor" and search for "app group". 要验证应用程序组是否已启用,请在“TextEditor”中打开下载的配置文件,然后搜索“app group”。 This will show you the result, if you have done it properly. 如果您已正确完成,这将显示结果。 Use these newly downloaded provisioning profiles ,and it will show you the check mark in capabilities. 使用这些新下载的配置文件,它将显示功能中的复选标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM