id、lat、lng、timestampをsqliteに保存しているので、JSONオブジェクトでサーバーに送信する必要があります。
ここにデータを挿入します。
NSString *insertStatement = [NSString stringWithFormat:@"INSERT INTO location (latitude, longitude, timeStamp) VALUES (%g, %g, %@)",newLocation.coordinate.latitude, newLocation.coordinate.longitude, newLocation.timestamp];
char *error;
if ( sqlite3_exec(databasehandle, [insertStatement UTF8String], NULL, NULL, &error) == SQLITE_OK)
{
NSLog(@"Location inserted. %@", newLocation.timestamp);
}
else NSLog(@"Error: %s", error);
そして、これが私が今取り組んでいるコードです。ここからどこに行けばいいのかわかりません:
NSString *queryStatement = [NSString stringWithFormat:@"SELECT ID, latitude, longitude, timeStamp FROM LOCATION"];
// Prepare the query for execution
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(databasehandle, [queryStatement UTF8String], -1, &statement, NULL) == SQLITE_OK)
{
// Iterate over all returned rows
while (sqlite3_step(statement) == SQLITE_ROW) {
これがデータの送信に使用したいJSON/HTTPコードです
responseData = [NSMutableData data];
//whatever your server address is
NSURL *url = [NSURL URLWithString:@"http://www.resturl.com/whatever"];
NSError *jsonError;
//NSJSONSerialization is Apple's new json serialization class so we can use it to convert to and from json and foundation objects
NSData *requestdata = [NSJSONSerialization dataWithJSONObject:returnArray options:0 error:&jsonError];
NSMutableURLRequest *request;
request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"%d", [requestdata length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:requestdata];
//this kicks off the request asynchronously
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
どんな助けでもいただければ幸いです!