在Watch Extension和iPhone上使用相同的启用iCloud的CoreData存储 [英] Using same iCloud enabled CoreData store across Watch Extension and iPhone

查看:389
本文介绍了在Watch Extension和iPhone上使用相同的启用iCloud的CoreData存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Apple Watch扩展程序打开启用iCloud CoreData商店时,我看到了一些奇怪的行为。
我在所有目标中使用相同的iCloud Container。

I'm witnessing some strange behaviour when opening iCloud Enabled CoreData store from Apple Watch Extension. I'm using the same iCloud Container across all targets.

这里是一个图片,显示了无处不在容器内的文件夹:

Here is a picture that shows what folder (ubiquity container) structure looks like inside the ubiquity container :

它似乎为iPhone&观看

It looks like it creates different stores for iPhone & Watch

我在iPhone应用程式&观看扩展。任何想法为什么这是发生?
如果我理解这正确,它对待iPhone应用程序&观看扩展作为单独的用户?

I'm sharing the same CoreData Stack between iPhone app & Watch Extension. Any ideas why this is happening ? If I understand this correctly it treats iPhone app & Watch Extension as a separate users ?

如果有人可以给出建议,我会非常感激。

I would really appreciate if someone could give an advice.

推荐答案

考虑让你的WatchKit扩展使用openParentApplication与父应用程序通信。使用openParentApplication很容易实现,并且有助于保持WatchKit扩展中的代码简单快捷。

Consider having your WatchKit Extension use openParentApplication to communicate with the parent app. Using openParentApplication is simple to implement and helps keep the code in the WatchKit extension simple and fast.

从WatchKit扩展InterfaceController调用openParentApplication。

From the WatchKit Extension InterfaceController, call openParentApplication.

NSDictionary *requst = @{@"request":@"myRequest"};

    [InterfaceController openParentApplication:requst reply:^(NSDictionary *replyInfo, NSError *error) {

            if (error) {
                NSLog(@"%@", error);
            } else {
                // DO STUFF
            }
        }];

然后,使用

 - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{

考虑在主应用程序中使用JSON数据(NSJSONSerialization)来响应手表扩展。

Consider also using JSON data (NSJSONSerialization) in the main app to respond to the watch extension.

这篇关于在Watch Extension和iPhone上使用相同的启用iCloud的CoreData存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆