2

QuickBlox在我的iOS应用程序中使用并尝试在Places表中添加数据

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];

但我无法添加地点。下面是控制台日志

休息请求:

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: 

休息响应:

<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>
4

1 回答 1

2

创建场所的正确方法是:

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];

在哪里:

  • geoDataID - QBLGeoData 对象的 ID
  • photoID - QBCBlob 对象的 ID

您的错误表明您必须使用照片创建文件,然后将其连接到位置。

要上传文件,请使用以下代码:

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);
    }
}

要创建 GeoData,请使用下一个代码:

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);
    }
}
于 2013-01-02T08:23:24.657 回答