I created a WatchKit app with a default Xcode template. I added permissions to the iOS Target app group, the Target App App App Target, and the Watchkit app extension app. (this is the name of the application group: group.com.lombax.fiveminutes) Then I tried to access the URL of the public folder using the iOS application and the WatchKit extension:
Extension:
@implementation ExtensionDelegate - (void)applicationDidFinishLaunching {
IOS app:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
However, test NSURL is different:
In iOS:
File: /// Users / Lombardo / Library / Developer / CoreSimulator / Devices / 38B983DB-342F-4A47-8C26-5D2C92CDB666 / data / Containers / Shared / AppGroup / 8DEE182E-AFE6-47DD-BA2B-6B0520158A8B /
on Watch:
File: /// Users / Lombardo / Library / Developer / CoreSimulator / Devices / BF52D613-25FF-4092-A5B2-9C3F1B616160 / data / Containers / Shared / AppGroup / CECB5EFC-7FBD-4C84-A878-1314CB7CF211 /
And for this reason, I cannot exchange data between the iOS application and the WatchKit extension.
I am trying to run a real device since I do not have WatchOS 2.0 on my Apple Watch. Any advice? Thanks
UPDATE I did some other tests:
- Installed by WatchOS 2, the problem still persists on real devices.
This is the store address for my iPhone:
NSURL * @ "file: ///private/var/mobile/Containers/Shared/AppGroup/3D05D159-94D6-409C-9A38-90E0830D0C3F/FiveMinutes.sqlite"
And this is the store address for my Watch:
NSURL * @ "file: ///private/var/mobile/Containers/Shared/AppGroup/F1E89377-F456-4FC2-BAAC-3DD705EF381A/FiveMinutes.sqlite"
Two applications read and write to two different .sqlite .
- In the simulator, if I hard-code one of the URLs, both the iOS simulator and the Watch simulator can read and write the same
.sqlite file and share the contents. However, this is not possible on real devices, since the Watch extension cannot be written to the iOS path:
URL: file: ///private/var/mobile/Containers/Shared/AppGroup/3D05D159-94D6-409C-9A38-90E0830D0C3F/FiveMinutes.sqlite parameters: (null) ... returned error Domain error = code NSCocoaErrorDomain = 512 " File cannot be saved. " UserInfo = {reason = Failed to create file; code = 2} using the dictionary userInfo {reason = "Could not create file; code = 2"; }
ios iphone ios-simulator watchkit apple-watch
Lombax
source share