1

我在我的视图控制器中运行它:

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

然后退出应用程序。

在我的 AppDelegate 中,我有:

- (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);

在我的 InterfaceController 我有:

- (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];

在 iPhone 应用程序中,我看到索引设置为整数 > 0 的日志。

为什么此字符串在应用程序之间不同步?我可以发送数组。是的,我已经配置了应用程序组,这就是 - (void)application:(UIApplication *)application handleWatchKitExtensionRequest:.. 将如何响应。

但是当我运行 Apple Watch 应用程序时,索引总是以@“0”的形式出现。

4

0 回答 0