2017-03-01 6 views
0

CloudSight APIをiOS Objective Cプロジェクトに実装しようとしましたが、何らかの理由で画像をcloudSightに送信しようとすると、cloudSightQueryパラメータがすべてnullに設定されます。cloudsight cloudSightQueryパラメータがnullに設定されました

私はCocoapodとしてアプリケーションにCloudSightを追加しました。すべてがうまくロードされます。このコードを実行すると、実際にはサーバーからの応答は返されません。

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

私達はちょうどこれを明確にするためのライブラリを更新しました。 pod update CloudSightを実行して新しいバージョンを取得することができます。

この種の問題の最も一般的な原因は、代理人が決して呼び出されないことです。通常、デリゲートオブジェクトはコールバックされる前に解放されますが、この場合、割り当てられるとnilのように見えます。

ここでこの行は:

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]; 

私たちは知ってみましょうそれが助けたら!

+0

このポッドの更新で問題が発生しました。午前中にもう一度お試しいただき、迅速な対応に感謝します。 – HurkNburkS

+0

そんなにうまくいきました! – HurkNburkS

関連する問題