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
只是在更新此窗格時遇到問題。將在早上再試一次,並讓你知道我如何去感謝你的快速反應! – HurkNburkS
非常工作謝謝! – HurkNburkS