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!
I have been through tons of S.O. posts, tried many different approaches and nothing works as expected.
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.
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)")
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:
Shared File Path on Watch: /private/var/mobile/Containers/Shared/AppGroup/94AA7797-528D-4E96-9623-23285BE0742B/watchPreview.mov
Shared File Path from iPhone: /private/var/mobile/Containers/Shared/AppGroup/4D43C314-CCBD-4861-BF90-69A8AC71198C/watchPreview.mov
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.
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.
So the big questions are:
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.
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.
See the Keeping your WatchOS content up-to-date page for more information on the topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With