Why is Apple Watch not syncing with App delegate & NSUbiquitousValueStore?

183 views Asked by At

I run this in my View Controller:

NSString *indexV = [NSString stringWithFormat:@"%d", index];
[[NSUbiquitousKeyValueStore defaultStore] setString:indexV forKey:@"index"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
indexV = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:@"index"];
NSLog(@"index V: %@", indexV);

Then quit the app.

In my AppDelegate I have:

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

    NSString *indexV = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:@"index"];
    NSLog(@"indexV: %@", indexV);

    NSDictionary *d = @{@"index" : indexV};
    reply(d);

In my InterfaceController I have:

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    [self sync];

- (void)sync {
    [WKInterfaceController openParentApplication:@{@"give" : @"give"} reply:^(NSDictionary *replyInfo, NSError *error) {
            NSLog(@"index: %@", replyInfo[@"index"]);
            if (replyInfo[@"index"]) {
                index = [replyInfo[@"index"] intValue];

In the iPhone app, I see the log where index is being set to an integer > 0.

Why is this string not synchronizing between apps? I am able to send arrays ok. Yes I have app groups configured, which is how - (void)application:(UIApplication *)application handleWatchKitExtensionRequest: .. will respond at all.

But when I run the Apple Watch app, index always comes through as @"0".

0

There are 0 answers