I am trying to implement the CloudSight API into an iOS Objective C project for fun, however for some reason when I try to send an image to cloudSight the cloudSightQuery parameters are all set to null.
I have added CloudSight to my application as a Cocoapod and everything loads fine and when I execute this code below it just never returns any kind of response from the server in fact I'm not even sure it sends.
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
Here's the library: https://libraries.io/github/cloudsight/cloudsight-objc
We just updated the library to make this clearer. You can run a pod update CloudSight to get the new version.
The most typical cause of this sort of problem is that the delegates are never being called. Usually, that means that the delegate object is released before being called back, however in this case it looks like it's nil when assigned.
This line here:
cloudSightQuery.queryDelegate = self;
[self searchWithImage];
Should be changed to:
[self searchWithImage];
And then in the method implementation change the initialization and start to:
// Start CloudSight
cloudSightQuery = [[CloudSightQuery alloc] initWithImage:imageData
atLocation:CGPointZero
withDelegate:self
atPlacemark:nil
withDeviceId:#""];
cloudSightQuery.queryDelegate = self;
[cloudSightQuery start];
Let us know if that helps!
Related
I cannot for the life of me figure out what is wrong here. I am working through a tutorial. I have double checked my typing. I have even copied and pasted the code but I am still getting this error.
#import "AddToDoItemViewController.h"
#interface AddToDoItemViewController ()
#end
#implementation AddToDoItemViewController
- (IBAction)textField:(id)sender {
}
- (IBAction)saveButton:(id)sender {
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (sender != self.saveButton) return;
if (self.textField.text.length > 0) {
self.toDoItem = [[ToDoItem alloc] init];
self.toDoItem.itemName = self.textField.text;
self.toDoItem.completed = NO;
}
}
#end
#interface AddToDoItemViewController ()
#property (strong, nonatomic) IBOutlet UIButton *saveButton;
#end
In the code you've posted here, your class does not have a property called saveButton. It has a method called saveButton:. So the error message appears to be correct.
i want to call a method "shows()" but why i am getting the error that "expected identifier or ( " and "use of undeclared identifier self"
ViewController.m
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
NSDictionary *inventory;
}
- (void)shows;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
inventory = #{#"Rahul":[NSNumber numberWithInt:11],
#"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)shows
{
NSLog(#"%#",inventory);
}
[self shows];
#end
You can't call [view shows]; in the class scope, you need to call it within a method, like in viewDidLoad
Call it like this:
- (void)viewDidLoad {
[super viewDidLoad];
inventory = #{#"Rahul":[NSNumber numberWithInt:11],
#"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
[self shows];//SHOWS call moved here...
}
You can't call this method outside. You can call it inside of anyother method. Like you can call this method in ViewDidLoad.
- (void)viewDidLoad {
[super viewDidLoad];
[self shows];
}
You have to place the code in another method, it can't be left in the open by it self.
Put it in your viewDidLoad: method or elsewhere
i need to change urlStr variable when my button clicked from another file. I'm writing my files; I explained everything i think too easy but hard for me please help me.
Thanks a lot.
Request.h file
#import <Foundation/Foundation.h>
#interface Request : NSObject{
}
Request.m file
#import "Request.h"
#import "MyViewController.h"
static NSString * const urlStr = #"http://google.com";
// I WANT TO CHANGE THIS urlStr WHEN storebutton CLICKED
#interface Request () {
BOOL reachable;
}
MyviewController.h file
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController{
}
#end
MyViewController.m file
#import "MyViewController.h"
#interface MyViewController ()
#end
#implementation MyViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)storebutton
{
NSString *urlStr = #"http://yahho.com"; // WHEN MY store button click action
}
#end
Make urlStr as static variable only, then create a static setter method for it inside Request.m and declare it in Request.h as shown below.
+ (void)setURLString:(NSString *) urlString
{
urlStr = urlString;
}
call this method on done button press as
-(void)storebutton
{
NSString *newURL = #"http://yahho.com";
[Request setURLString:newURL];
}
Just wanted to get a sanity check on this code for storing and retrieving user data for iOS 7. It's not working but I'm not seeing the issue.
GameData.h
#import <Foundation/Foundation.h>
#interface GameData : NSObject<NSCoding>
{
int HighScoreGD;
}
#property (readwrite,assign) int HighScoreGD;
#end
extern GameData *gGameData;
GameData.m
#import "GameData.h"
GameData *gGameData;
#implementation GameData
#synthesize HighScoreGD;
-(void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInt:HighScoreGD forKey:#"HighScoreGD"];
}
-(id)initWithCoder:(NSCoder *)coder {
if((self = [super init])) {
HighScoreGD = [coder decodeIntForKey:#"HighScoreGD"];
}
return self;
}
-(id) init {
if((self = [super init])) {
}
return self;
}
-(void) dealloc {
//[super dealloc];
}
#end
Storing data:
gGameData.HighScoreGD = pointsHigh;
Retrieving data:
pointsHigh = gGameData.HighScoreGD;
I had used this in a bunch of old game concepts (cocos2d) in the past and it worked fine.
Not getting compile errors. Just simply isn't storing the data.
I haven't used this code in a couple years and it's not working. Did iOS7 or cocos2d v3 change how NSCoder is used?
Or am I making a dumb error somewhere?
Thanks in advance.
I am using JKExpandTableView and I want to reload JKExpandTableview. Currently Im calling reloadData method on JKExpandTableView object but it will not call data source delegate method. Thanks.
My header file is like below:
#import "JKExpandTableView.h"
#interface IncidentsViewController : UIViewController <JKExpandTableViewDelegate, JKExpandTableViewDataSource>
#property(nonatomic,weak) IBOutlet JKExpandTableView * expandTableView;
#property(nonatomic,strong) NSMutableArray * dataModelArray;
-(void)refreshIncidentsModule;
#end
And my IncidentsController.m is:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view
[self initializeSampleDataModel];
self.expandTableView.tableViewDelegate = self;
self.expandTableView.dataSourceDelegate = self;
[self deviceOrientationDidChangeNotification:nil];
}
-(void)refreshIncidentsModule
{
[self initializeSampleDataModel];
[self.expandTableView reloadData];
}
in your viewDidLoad method set delegate and datasource.something like followings:
- (void)viewDidLoad
{
self.expandTableView.tableViewDelegate = self;
self.expandTableView.dataSourceDelegate = self;
}