Question

I am using QuickBlox in my iOS app and trying to add data in Places table

QBLPlace *place = [QBLPlace place];
place.geoDataID = 34691;
place.photoID = 447;
place.title = [NSString stringWithFormat:@"%@",[aView.annotation title]];
place.address = @"London, Gadge st, 34";
place.placeDescription = @"My place description";
place.latitude = pinLocation.coordinate.latitude;
place.longitude = pinLocation.coordinate.longitude;
[QBLocation createPlace:place delegate:self];

but I am not able to add place. Below is the console log

RestRequest:

POST http://api.quickblox.com/places.xml
headers:{
"QB-SDK" = "iOS 1.3.1";
"Qb-Token" = c1191ff8ffbfdb79b11fba6bf2a4c054d2644de8;
"QuickBlox-REST-API-Version" = "0.1.1";
}
parameters:{
"place[address]" = "London, Gadge st, 34";
"place[description]" = "My place description";
"place[geo_data_id]" = 34691;
"place[photo_id]" = 447;
"place[title]" = "The Bridge Room";
}
raw body:place[address]=London%2C%20Gadge%20st%2C%2034&place[description]=My%20place%20description&place[geo_data_id]=34691&place[photo_id]=447&place[title]=The%20Bridge%20Room
2013-01-02 10:21:14.543 Chat.Points[10229:1d903] Query QBLPlaceCreateQuery DEALLOC
2013-01-02 10:21:14.551 Chat.Points[10229:1d903] Request finished, response: 

RestResponse:

<QBASIHTTPRequest: 0xb40fc00>
headers:{
"Access-Control-Allow-Origin" = "*";
"Access-Control-Request-Method" = "*";
"Cache-Control" = "no-cache";
Connection = Close;
"Content-Length" = 116;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Wed, 02 Jan 2013 04:51:14 GMT";
"QuickBlox-REST-API-Version" = "0.1.1";
Server = "nginx/1.0.15";
Status = "422 Unprocessable Entity";
"X-Rack-Cache" = "invalidate, pass";
"X-Request-Id" = 5ad6e7d628b4fbd931b7896058f012cd;
"X-Runtime" = "0.052140";
"X-UA-Compatible" = "IE=Edge,chrome=1";
}
body:<?xml version="1.0" encoding="UTF-8"?>
<errors type="array">
<error>No photo with such id found</error>
</errors>
Was it helpful?

Solution

The right way to create place is:

QBLPlace *place = [QBLPlace place];
place.geoDataID = 34691;
place.photoID = 447;
place.title = [NSString stringWithFormat:@"%@",[aView.annotation title]];
place.address = @"London, Gadge st, 34";
place.placeDescription = @"My place description";

[QBLocation createPlace:place delegate:self];

where:

  • geoDataID - ID of QBLGeoData object
  • photoID - ID of QBCBlob object

Your error says that you have to create file with photo and then connect it to place.

To upload file please use this code:

NSData *file = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Hotel47" ofType:@"png"]];

[QBContent TUploadFile:file fileName:@"Hotel47 Image" contentType:@"image/png" isPublic:YES delegate:self]; 

#pragma mark -
#pragma mark QBActionStatusDelegate

- (void)completedWithResult:(Result *)result{
    // Upload file result
    if(result.success && [result isKindOfClass:[QBCFileUploadTaskResult class]]){
        // File uploaded, do something

        QBCBlob *uploadedFile  = ((QBCFileUploadTaskResult *)result).uploadedBlob;

        NSUInteger photoID = uploadedFile.ID; // use this as photo IS for place
    }else{
        NSLog("errors=%@", result.errors);
    }
}

To create GeoData please use next code:

QBLGeoData *geodata = [QBLGeoData geoData];
geodata.latitude = 23.2344;
geodata.longitude = -12.23523;
geodata.status = @"Hello, world";

[QBLocation createGeoData:geodata delegate:self];

#pragma mark -
#pragma mark QBActionStatusDelegate

- (void)completedWithResult:(Result *)result{
    // Check-in result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        QBLGeoDataResult *checkinResult = (QBLGeoDataResult *)result;

        NSUInteger geoDataID = checkinResult.geoData.ID; // your geo data ID
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top