2017-03-01 62 views
0

我試圖將CloudSight API實現到iOS Objective C項目中以獲得樂趣,但是由於某些原因,當我嘗試將圖像發送到cloudSight時,cloudSightQuery參數都設置爲null。cloudsight cloudSightQuery參數設置爲空

我已經將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

我們剛剛更新了庫,使之更清楚。您可以運行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]; 

讓我們知道如果有幫助!

+0

只是在更新此窗格時遇到問題。將在早上再試一次,並讓你知道我如何去感謝你的快速反應! – HurkNburkS

+0

非常工作謝謝! – HurkNburkS