-1

I'm creating a iWatch app in which I need to display an array of images. I'm using WCSession to transfer the images from the iPhone. Here is the code I tried:

InterfaceController.m

- (void)willActivate {
    [super willActivate];

   if ([WCSession isSupported]) {

    WCSession *session = [WCSession defaultSession];
    session.delegate = self;
    [session activateSession];

    NSLog(@"WCSession is supported");
}

- (void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary<NSString *,id> *)applicationContext {
    NSLog(@"%@", applicationContext);

    NSData *imageData = applicationContext[@"image"];
    UIImage *contactImage = [UIImage imageWithData:imageData];
    _graphImage = [contactImage valueForKey:@"image"];
}

In my iPhone app, I have an array which stores the images in bytes. After executing the iWatch app, I'm getting the NSData value from my iPhone app. But the app terminates at UIImage *contactImage = [UIImage imageWithData:imageData]; with

[__NSCFArray length]: unrecognized selector sent to instance.

I googled this error but not able to find a solution in my case.

Any help will be greatly appreciated.

  • 5
    Means your `imageData` is actually an `NSArray` – dan Mar 25 '16 at 13:06
  • 2
    If you're new, why not learn Swift? Type checking would make your code more safe and `as?` would have avoided a crash from such an error. –  Mar 25 '16 at 13:18
  • @dan yes actually the applicationContext contains the response from iphone app. So imageData is actually an NSArray – Jestin Saji Chacko Mar 25 '16 at 13:27

1 Answers1

-1

You're getting this error because there is missplaced type -_graphImage = [contactImage valueForKey:@"image"]; - here your are sending valueForKey for image instance

Karaban
  • 151
  • 8