cloudight cloudSightQuery参数设置为null

时间:2017-03-01 09:20:40

标签: ios objective-c cloudsight

我正在尝试将CloudSight API实现到iOS Objective C项目中以获得乐趣,但是出于某种原因,当我尝试将图像发送到cloudSight时,cloudSightQuery参数都被设置为null。

我已将CloudSight作为Cocoapod添加到我的应用程序中并且所有内容都正常加载,当我执行下面的代码时,它实际上永远不会从服务器返回任何类型的响应,实际上我甚至不确定它是否发送。

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

这是图书馆:https://libraries.io/github/cloudsight/cloudsight-objc

1 个答案:

答案 0 :(得分:1)

我们刚刚更新了库以使其更清晰。您可以运行pod update CloudSight来获取新版本。

此类问题的最典型原因是代理人永远不会被调用。通常,这意味着委托对象在被回调之前被释放,但是在这种情况下,它在分配时看起来是零。

这一行:

cloudSightQuery.queryDelegate = self;
[self searchWithImage];

应改为:

[self searchWithImage];

然后在方法实现中更改初始化并开始:

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

如果有帮助,请告诉我们!