iPhone和Apple Watch不共享App组 [英] iPhone and Apple Watch not sharing App Group

查看:207
本文介绍了iPhone和Apple Watch不共享App组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为这个问题拉了两天了.我在iPhone应用程序中生成了一个小电影文件,该文件要从iPhone发送以在Apple Watch上播放.作为概念证明,我在Apple Watch App捆绑包中放置了一个类似的.mov,并且可以毫无问题地播放它.因此,我想了想,现在我想将一个新的小片段发送到手表时,只需将其放入应用程序组共享"容器中,然后从那里访问它即可,而不是从捆绑包中访问它.不!

I've been pulling my hair out over this problem for two days now. I generate a small movie file in the iPhone App that I want to send from the iPhone to play on an Apple Watch. As I proof of concept, I put a similar .mov in the Bundle of the Apple Watch App and was able to play it with no problems. So I figured, easy peasy, now when I want to send a new little clip to the watch, I will just put it in an App Group Shared container and access it from there instead of from the Bundle. Nope!

我经历了数吨的S.O.帖子,尝试了许多不同的方法,但没有任何预期的效果.

I have been through tons of S.O. posts, tried many different approaches and nothing works as expected.

在您询问之前,我已对应用程序组进行了多次重做,从iTunes Connect中删除了旧的应用程序组,重新生成了配置文件,多次清理了目标,多次删除了DerivedData,删除了应用程序并重新开始几次,几乎尝试了所有我可以在SO上找到的小调整和修复没有任何帮助.

Before you ask, I have re-done the App Group several times, deleted the old ones from iTunes Connect, re-generated provisioning profiles, cleaned the targets numerous times, deleted the DerivedData several times, deleted the apps and started over several times and tried virtually every little tweak and fix I could find on S.O. Nothing helps.

我认为我知道问题出在哪里,但不知道如何解决.

I do think I know what the problem is, but have no idea how to conquer it.

这是我在iPhone App和Watch App中都使用的代码,用于获取共享容器的路径(如果是从Watch端,则此代码段):

Here is the code that I use in both the iPhone App and the Watch App to get a path to the shared container (this snippet if from the Watch side):

let fileManager = FileManager.default
    let sharedContainer = fileManager
        .containerURL(
            forSecurityApplicationGroupIdentifier: "group.com.mycompany.myappname")

    let dirPath = sharedContainer?.path
     sharedFilePathOnWatch = (dirPath! as NSString).appendingPathComponent("watchPreview.mov")

    print ("Shared File Path on Watch: \(sharedFilePathOnWatch)")
    print ("Shared File Path from iPhone: \(sharedFilePath)")

打印语句显示了我从iPhone(通过Watch Connectivity)发送到手表的共享文件路径以及Watch App解析的共享路径.

The print statements show me the Shared file path that I send over to the watch from the iPhone (via Watch Connectivity) and the Shared Path that the Watch App resolves.

我在运行以下命令时会得到什么:

What I get when this runs it the following:

观看时的共享文件路径:/private/var/mobile/Containers/Shared/AppGroup/94AA7797-528D-4E96-9623-23285BE0742B/watchPreview.mov

Shared File Path on Watch: /private/var/mobile/Containers/Shared/AppGroup/94AA7797-528D-4E96-9623-23285BE0742B/watchPreview.mov

iPhone的共享文件路径:/private/var/mobile/Containers/Shared/AppGroup/4D43C314-CCBD-4861-BF90-69A8AC71198C/watchPreview.mov

Shared File Path from iPhone: /private/var/mobile/Containers/Shared/AppGroup/4D43C314-CCBD-4861-BF90-69A8AC71198C/watchPreview.mov

现在,我期望只有一个共享容器,并且iPhone和Watch都应解析相同的路径,但事实并非如此.我还注意到,在多次运行中,这两个应用程序的这些路径保持不变.这不是一个动态地址,我每次运行都会怀疑一段时间.

Now I was expecting that there would be only one shared container and that both the iPhone and the Watch should resolve the same path, but this is not the case. I've also noticed that these paths remain constant for the two apps over multiple runs. It's not a dynamic address that is changing every time I run as I suspected for awhile.

作为使此功能发挥作用的最后一次尝试,我发现由于我有通向iPhone上的共享容器和Apple Watch上的共享容器的路径,也许我可以将文件从一个移到另一个因为,好,他们应该共享.但是,即使那样也不行.

As a last ditch attempt to get this to function, I figured that since I had a path to the shared container on the iPhone and the shared container on the Apple Watch, maybe I could just move the file from one to the other because, well, they are supposed to be sharing. But no, even that doesn't work.

因此,主要问题是:

  1. 为什么我要在共享应用程序上解析两条不同的路径
  2. 我如何将我的小电影文件从iPhone传输到Apple Watch

推荐答案

随着watchOS2和本机watchOS应用程序的引入,Apple Watch应用程序不再仅仅是其iOS同类产品的扩展,因此它们不再共享应用组.

With the introduction of watchOS2 and native watchOS apps, Apple Watch apps are no longer just extensions of their iOS counterpart and hence they don't share AppGroups.

您不能使用AppGroup从watchOS2开始共享数据.您必须使用WatchConnectivity框架在iOSwatchOS应用之间发送数据.

You cannot use AppGroups for sharing data from watchOS2 onwards. You have to use the WatchConnectivity framework for sending data between your iOS and watchOS apps.

请参见 WatchKit编程指南-共享数据页面以获取有关该主题的更多信息.

See the WatchKit Programming Guide - Sharing Data page for more information on the topic.

这篇关于iPhone和Apple Watch不共享App组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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