HurkNburkS
HurkNburkS

Reputation: 5510

cloudsight cloudSightQuery parameters set to null

I am trying to implement the CloudSight API into an iOS Objective C project for fun, however for some reason when I try to send an image to cloudSight the cloudSightQuery parameters are all set to null.

I have added CloudSight to my application as a Cocoapod and everything loads fine and when I execute this code below it just never returns any kind of response from the server in fact I'm not even sure it sends.

firstview.h

#import <UIKit/UIKit.h>


#import "CloudSight.h"
#import <CloudSight/CloudSightQueryDelegate.h>


@interface FirstViewController : UIViewController <CloudSightQueryDelegate>
{
    CloudSightQuery *cloudSightQuery;
}

- (void)searchWithImage;
- (NSData *)imageAsJPEGWithQuality:(float)quality;

@end

firstview.m

#import "FirstViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "CloudSightConnection.h"
#import "UIImage+it_Image.h"
#import <CloudSight/CloudSightQuery.h>


@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    cloudSightQuery.queryDelegate = self;
    [self searchWithImage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)searchWithImage {
    UIImage * myImage = [UIImage imageNamed: @"car.jpg"];
    NSData *imageData = [self imageAsJPEGWithQuality:0.7 image:myImage];




    // Start CloudSight
    cloudSightQuery = [[CloudSightQuery alloc] initWithImage:imageData
                                                  atLocation:CGPointZero
                                                withDelegate:self
                                                 atPlacemark:nil
                                                withDeviceId:@""];

    [cloudSightQuery start];
}

#pragma mark CloudSightQueryDelegate

- (void)cloudSightQueryDidFinishIdentifying:(CloudSightQuery *)query {
    if (query.skipReason != nil) {
        NSLog(@"Skipped: %@", query.skipReason);
    } else {
        NSLog(@"Identified: %@", query.title);
    }
}

- (void)cloudSightQueryDidFail:(CloudSightQuery *)query withError:(NSError *)error {
    NSLog(@"Error: %@", error);
}

#pragma mark image
- (NSData *)imageAsJPEGWithQuality:(float)quality image:(UIImage *)image
{
    return UIImageJPEGRepresentation(image, quality);
}



@end

Here's the library: https://libraries.io/github/cloudsight/cloudsight-objc

Upvotes: 0

Views: 54

Answers (1)

Brad Folkens
Brad Folkens

Reputation: 986

We just updated the library to make this clearer. You can run a pod update CloudSight to get the new version.

The most typical cause of this sort of problem is that the delegates are never being called. Usually, that means that the delegate object is released before being called back, however in this case it looks like it's nil when assigned.

This line here:

cloudSightQuery.queryDelegate = self;
[self searchWithImage];

Should be changed to:

[self searchWithImage];

And then in the method implementation change the initialization and start to:

// Start CloudSight
cloudSightQuery = [[CloudSightQuery alloc] initWithImage:imageData
                                              atLocation:CGPointZero
                                            withDelegate:self
                                             atPlacemark:nil
                                            withDeviceId:@""];
cloudSightQuery.queryDelegate = self;
[cloudSightQuery start];

Let us know if that helps!

Upvotes: 1

Related Questions