1

我正在尝试使用 App Delegate 中的以下方法将数组发送到 InterfaceController:

- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply
{
NSLog(@"Request received by iOS app");

NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:20];

for (NSDictionary *object in [[NSUserDefaults standardUserDefaults] objectForKey:@"reminders"]) {

    NSString *subject = object[@"subject"];
    [mutableArray addObject:subject];
}

NSLog(@"MUTABLE ARRAY: %@", mutableArray);

NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:mutableArray, @"key", nil];


reply(dictionary);
}

在接口控制器中:

- (IBAction)callPhoneAppButtonTapped
{
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"text to display", @"key", nil];


[InterfaceController openParentApplication:dictionary reply:^(NSDictionary *replyInfo, NSError *error) {

 NSLog(@"Reply received by Watch app: %@", replyInfo);


}];
}

问题是我可以在 App Delegate 中看到数组,但在 Apple Watch 的 InterfaceController 中看不到回复?

关于这种方法或将数组发送到 InterfaceController 以创建表的更好方法的任何建议?

4

1 回答 1

1

在 watchOS2 中,他们引入了一个很好的功能,称为 WatchConnectivity。请看我对这个问题的回复:How to send data from Iphone to Apple Watch in OS2 in Objective-C

它很容易发送一个数组而不是 String/NSNumber。

于 2015-07-07T09:24:09.573 回答