gpt4 book ai didi

ios - cloudsight cloudSightQuery 参数设置为空

转载 作者:行者123 更新时间:2023-11-29 00:28:06 25 4
gpt4 key购买 nike

为了好玩,我正在尝试将 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

最佳答案

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

此类问题的最典型原因是从未调用委托(delegate)。通常,这意味着委托(delegate)对象在被回调之前被释放,但是在这种情况下,它在分配时看起来像是 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];

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

关于ios - cloudsight cloudSightQuery 参数设置为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com