1

I am trying to send an array to the InterfaceController with the following method within the App Delegate:

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

And in the Interface Controller:

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


}];
}

The problem is I can see the array in the App Delegate but I cannot read the reply in the InterfaceController of the Apple Watch?

Any suggestions on this approach or a better approach to send an array to the InterfaceController in order to create a Table?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ibjazz
  • 263
  • 5
  • 17
  • What do you mean by "cannot read the reply"? Is it a nil reply dict, or is it a malformed dictionary? Does the log `NSLog(@"Reply received by Watch app: %@", replyInfo);` get hit at all? Also try to print out the error: `if (error) NSLog(@"error=%@", error);` – SeaJelly Jul 07 '15 at 00:09
  • 1
    http://stackoverflow.com/questions/31178664/how-to-send-data-from-iphone-to-apple-watch-in-os2-in-objective-c/31180249#31180249 – Philip Jul 07 '15 at 09:22
  • In your case if you are debugging the watch kit extension (where you can see the dictionary in the request) you can't debug at the same time the companion App... you should use Debug->Attach to process and select your App. Then you should see the reply in the interface controller. – Lorenzo Jul 21 '15 at 05:30

1 Answers1

1

In watchOS2 they introduces a nice feature called WatchConnectivity. Please look at my reply to this question: How to send data from Iphone to Apple Watch in OS2 in Objective-C

Its easy to send an array instead of String/NSNumber.

Community
  • 1
  • 1
Philip
  • 2,287
  • 1
  • 22
  • 37