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>
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);
}
}
Related
I'm trying to parse tweets using Twitter Framework, so I write the following code and it's working fine, but it's not Synchronous.
Now I'm trying to get all the tweets from #iOS.
I have used the following code to get the search result for iOS hashtag:
-(void)fetchResults
{
// Do a simple search, using the Twitter API
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
#"http://search.twitter.com/search.json?q=iOS%20&rpp=20&with_twitter_user_id=true&result_type=recent"]
parameters:nil requestMethod:TWRequestMethodGET];
// Notice this is a block, it is the handler to process the response
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
NSLog(#"Twitter response: %#", [dict description]);
[self filterTweets];
}
else
NSLog(#"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}
As a result I got this:
Twitter response: {
"completed_in" = "0.007";
"max_id" = 333837474914766848;
"max_id_str" = 333837474914766848;
page = 1;
query = quranRadios;
"refresh_url" = "?since_id=333837474914766848&q=quranRadios&result_type=recent";
results = (
{
"created_at" = "Mon, 13 May 2013 06:53:51 +0000";
"from_user" = YousefMutawe;
"from_user_id" = 324385406;
"from_user_id_str" = 324385406;
"from_user_name" = "Yousef N Mutawe \Uf8ff";
geo = "<null>";
id = 333837474914766848;
"id_str" = 333837474914766848;
"iso_language_code" = pt;
metadata = {
"result_type" = recent;
};
"profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
"profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
source = "<a href="http://twitter.com/download/iphone">Twitter for iPhone</a>";
text = "Testing #quranRadios #Mkalatrash";
},
{
"created_at" = "Sun, 12 May 2013 13:09:43 +0000";
"from_user" = YousefMutawe;
"from_user_id" = 324385406;
"from_user_id_str" = 324385406;
"from_user_name" = "Yousef N Mutawe \Uf8ff";
geo = "<null>";
id = 333569679484416000;
"id_str" = 333569679484416000;
"iso_language_code" = et;
metadata = {
"result_type" = recent;
};
"profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
"profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
source = "<a href="http://twitter.com/download/iphone">Twitter for iPhone</a>";
text = "#quranRadios :)";
}
);
"results_per_page" = 20;
"since_id" = 0;
"since_id_str" = 0;
}
So i use the following method to filter the result and to get the (Tweet,Username,and the User image):
-(void)filterTweets
{
NSArray *results = [dict objectForKey:#"results"];
//Loop through the results
int x =0;
for (NSDictionary *tweet in results)
{
// Get the tweet
NSString *twittext = [tweet objectForKey:#"text"];
NSString *twitPic = [tweet objectForKey:#"profile_image_url"];
NSString *userName = [tweet objectForKey:#"from_user"];
// Save the tweet to the twitterText array
[tweetsInfo addObject:(twittext)];
[tweetPics addObject:(twitPic)];
[imagesArray addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[tweetPics objectAtIndex:x]]]]];
[userNameTweet addObject:userName];
x++;
//NSLog(#"tweet ooooooo ======> %#",twitPic);
countMe++;
}
[tweetsTable reloadData];
}
I'm not sure if i'm doing the right thing,so what would you recommend me to do? and how can i make it synchronized?
am new to programming iOS, please advice.
Thanks.
Sorry for the long question but that best summarizes what I am trying to do:
My JSON Looks like:
{
4e8cf1d6c7e24c063e000000 = {
"_id" = {
"$id" = 4e8cf1d6c7e24c063e000000;
};
author = faisal;
comments = (
{
author = adias;
comment = amazing;
},
{
author = nike;
comment = "I concur";
}
);
created = {
sec = 1317772800;
usec = 0;
};
text = "This is a random post";
title = "post # 1";
type = (
punjabi
);
};
4e91fd49c7e24cda74000000 = {
"_id" = {
"$id" = 4e91fd49c7e24cda74000000;
};
author = draper;
comments = (
{
author = adias;
comment = "amazing again";
}
);
created = {
sec = 1318118400;
usec = 0;
};
text = "This is a random post again";
title = "post # 2";
type = (
punjabi
);
};
}
What I would like to do is to ultimately have a UTTableview with each row having a title (text from above JSON):
This is the code I have so far:
NSString *responseString = [request responseString];
NSDictionary *resultsDictionary = [responseString objectFromJSONString];
How do I put everything in an array for the UITableView? Again I am just a little rusty as I can swear I have done that before.
If you don't need the keys then you can convert it to an array by using allValues, e.g.:
NSArray *values = [resultsDictionary allValues];
Does your JSON really parse to an NSDictionary, or is this an NSArray containing NSDictionary instances? If the latter, then isn't it just something like:
NSString *textForCell = [[resultsArray objectAtIndex:row] valueForKey:#"title"];
I have one NSMutableArray called SubList that contains 262 element. Every object is a NSDictionary!
This code works like a charm!
for (NSDictionary *element in listSub){
[cell.textLabel setText:[element objectForKey:#"title"]];
}
But if I try to use use this code I get a SIGBART error!
NSDictionary * element = [listSub objectAtIndex:[indexPath row]];
[cell.textLabel setText:[element objectForKey:#"title"]];
So what's the problem?
*EDit the problem is at this line
NSDictionary * element = [listSub objectAtIndex:[indexPath row]];
and this is the description
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet objectAtIndex:]: unrecognized selector sent to instance 0x89a8d90'
Thanks
**Edit
This is the output of listSub!
listSub: {(
{
categories = (
{
id = "user/14761688561595773457/label/Web Programming";
label = "Web Programming";
}
);
firstitemmsec = 1265885595862;
id = "feed/http://feeds.feedburner.com/FamousBloggers";
sortid = A11327DE;
title = "Famous Bloggers";
},
{
categories = (
{
id = "user/14761688561595773457/label/Hacking";
label = Hacking;
}
);
firstitemmsec = 1241258413829;
htmlUrl = "http://backtrack-italia.blogspot.com/";
id = "feed/http://feeds2.feedburner.com/BackTrackItalia";
sortid = E8A04F76;
title = "Back Track Italia";
},
{
categories = (
{
id = "user/14761688561595773457/label/Hacking";
label = Hacking;
}
);
firstitemmsec = 1245376992188;
htmlUrl = "http://www.offensive-security.com";
id = "feed/http://www.offensive-security.com/blog/feed/";
sortid = 92F57555;
title = "BackTrack Information Security Distribution";
},
{
categories = (
{
id = "user/14761688561595773457/label/iOS Developer";
label = "iOS Developer";
}
);
firstitemmsec = 1296830392306;
htmlUrl = "http://amix.dk/Main/";
id = "feed/http://feeds.feedburner.com/amixdk";
sortid = 110C52C3;
title = "amix.dk blog";
},
{
categories = (
{
id = "user/14761688561595773457/label/Apple News";
label = "Apple News";
}
);
firstitemmsec = 1285261350202;
htmlUrl = "http://www.appletvhacks.net";
id = "feed/http://www.appletvhacks.net/feed/";
sortid = 81125D2E;
title = "Apple TV Hacks";
},
{
categories = (
{
id = "user/14761688561595773457/label/Apple News";
label = "Apple News";
}
);
firstitemmsec = 1293230300220;
htmlUrl = "http://www.appletvitalia.it";
id = "feed/http://www.appletvitalia.it/feed/";
sortid = 892FE61C;
title = "Apple Tv Italia";
},
{
categories = (
{
id = "user/14761688561595773457/label/Apple News";
label = "Apple News";
}
);
firstitemmsec = 1270115980935;
htmlUrl = "http://www.appleecious.com";
id = "feed/http://feeds2.feedburner.com/appleecious";
sortid = 00B5AFC2;
title = Appleecious;
},
{
categories = (
{
id = "user/14761688561595773457/label/Hacking";
label = Hacking;
}
);
firstitemmsec = 1258495136927;
htmlUrl = "http://www.rawseo.com/news";
id = "feed/http://www.rawseo.com/news/feed/";
sortid = D6766911;
title = "A blend of programming and seo";
},
{
categories = (
{
id = "user/14761688561595773457/label/Seo e Web Marketing";
label = "Seo e Web Marketing";
}
);
firstitemmsec = 1233684720758;
htmlUrl = "http://it-adsense.blogspot.com/";
id = "feed/http://it-adsense.blogspot.com/atom.xml";
sortid = 9FB570ED;
title = "AdSense Blog-Italiano";
},
{
categories = (
);
firstitemmsec = 1277627346000;
htmlUrl = "http://aext.net";
id = "feed/http://feeds.feedburner.com/aextnet";
sortid = 70800CFE;
title = "AEXT.NET NET MAGAZINE";
},
{
categories = (
);
firstitemmsec = 1217001547735;
htmlUrl = "http://www.alessandroscoscia.it";
id = "feed/http://feeds.feedburner.com/alessandroscoscia";
sortid = 51CB8E6E;
title = "Alessandro Scoscia";
},
{
categories = (
{
id = "user/14761688561595773457/label/iOS Developer";
label = "iOS Developer";
}
);
...
I'm sure that it isn't a NSSet.
Now I post the code that I'm using to populate my array.
NSError *error;
NSURLResponse *response;
NSData *dataReply = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *string = [[NSString alloc] initWithData:dataReply encoding:NSASCIIStringEncoding];
NSLog(#"testing %#",string);
SBJsonParser *vol= [[SBJsonParser alloc]init];
if (string) {
NSArray *feeds = [vol objectWithString:string error:nil];
NSDictionary *results = [string JSONValue];
NSArray *subs = [results valueForKey:#"subscriptions"];
for (NSDictionary *iscrizione in subs){
[subscriptions addObject:iscrizione];
}
This is part of another class and also in this part of my code if i try to do something like this:
NSDictionary * element = [listSub objectAtIndex:0];
NSLog([element objectForKey:#"title"]);
I get the same error while if I try a loop like this
for (NSDictionary *element in listSub){
[cell.textLabel setText:[element objectForKey:#"title"]];
}
Everythings works fine without NSSet errors. This make me crazy!
The problem is probably that listSub was not properly retained and therefore released already. The memory is now re-used and the object at that address is now an __NSCFSet, which does not respond to objectAtIndex:.
Note that autoreleased objects returned by a convenience class method like [NSMutableArray arrayWithXXX] should be retained and only released when not needed anymore. The best way to be sure they are retained is to declare a #property(retain) NSArray *subList, #synthesize it and use self.subList in all cases except perhaps in dealloc.
Addition
It was suggested that the method that created subList returned a set and not an array. If that were the case, the simple loop at the begining of the answer would not function either. That is why I find it very unlikely that subList was originally an NSSet, and much more likely that the array was overreleased and dealloced and the memory re-used for the NSSet.
Please do what people who want to help you ask of you.
Add the line
NSLog(#"listSub: %#", listSub);
at the place where listSub is set and also right before the error line. Then look in the error log what it displays and tell us.
Have you tried:
[cell.textLabel setText:[element objectForKey:#"title"]];
What is that "lol"??
listSub isn't an array, it's an NSSet.
problem is here
[cell.textLabel setText:[NSString stringWithFormat:[element objectForKey:#"title"]]];
when you are call stringWithFormat then you need to give format in string literal form like this
[cell.textLabel setText:[NSString stringWithFormat:#"%#",[element objectForKey:#"title"]]];
or direct set the text with out calling stringWithFormat:
your array got released some where, so for solving the problem you need to call retain on tyour array at right place.
Just try this one.
NSDictionary * element = [listSub objectAtIndex:[indexPath row]];
[cell.textLabel setText:[NSString stringWithFormat:#"%#",[element objectForKey:#"title"]]];
Or try this as you have edit your question, Edit
NSDictionary *element = [[NSDictionary alloc] initWithDictionary:[listSub objectAtIndex:indexPath.row]];
[cell.textLabel setText:[element objectForKey:#"title"]];
[element release];
Hello I want to set following key Values for Dictionary
{
application = {
id = 136664723060869;
name = Iphoneapp;
};
caption = "bit.ly";
comments = {
count = 2;
data = (
{
"created_time" = "2011-06-14T07:39:45+0000";
from = {
id = 100001507678574;
name = "Widevision Dev";
};
id = "100001507678574_164163733643881_1822049";
likes = 1;
message = hi;
},
{
"created_time" = "2011-06-14T08:17:31+0000";
from = {
id = 100001507678574;
name = "Widevision Dev";
};
id = "100001507678574_164163733643881_1822143";
message = hmmm;
}
);
};
I want to post comments ={ data ={ id = , name = }}
I used following code for this
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:#"Good Afternoon" forKey:#"message"];
NSLog(#"%#",variables);
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"id/comments" withPostVars:variables];
NSLog(#"postMeFeedButtonPressed: %#", fb_graph_response.htmlResponse);
But this not working....How can I post message in comment object
Please check the code below:
NSMutableDictionary *comments = [[NSMutableDictionary alloc] init];
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
NSMutableDictionary *from = [[NSMutableDictionary alloc] init];
[from setObject:#"100001507678574" forKey:#"id"];
[from setObject:#"Widevision Dev" forKey:#"name"];
[data setObject:from forKey:#"from"];
[comments setObject:data forKey:#"comments"];
NSLog(#"%#",comments);
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"id/comments" withPostVars:comments];
I'm developing an Twitter app, but in the view where's supposed to be the logged user info, I'm not able to parse the JSON gave by [_engine getUserInformationFor:username];. I'm using SBJSON and tells me this when tries to parse it:
2011-05-07 12:29:45.553 BirdieApp[7122:40b] -JSONValue failed. Error is: Unrecognised leading character at offset 0
This is the code I'm using:
NSLog(#"loggedapi");
NSString *username = [_engine username];
NSString *userinfo = [_engine getUserInformationFor:username];
NSLog(#"user: %#%#", username, userinfo);
NSArray *results = [userinfo JSONValue];
NSDictionary *first = [results objectAtIndex:0];
NSLog(#"screen name = %#", [first objectForKey:#"description"]);
The output that [_engine getUserInformationFor:username]; gaves me is:
2011-05-07 12:29:46.281 BirdieApp[7122:40b] User Info Received: (
{
"contributors_enabled" = false;
"created_at" = "Fri Sep 17 20:40:15 +0000 2010";
"default_profile" = true;
"default_profile_image" = false;
description = "iPhone developer and Photoshop designer. \U30dd\U30fc\U30eb. I developed a web browser, it's called zad0xNET browser, search it in Cydia. Ofcourse this is a fake account!";
"favourites_count" = 0;
"follow_request_sent" = false;
"followers_count" = 4;
following = 0;
"friends_count" = 1;
"geo_enabled" = true;
id = 191964939;
"is_translator" = false;
lang = es;
"listed_count" = 0;
location = "Castilla y Le\U00f3n, Espa\U00f1a";
name = zad0xLOL;
notifications = false;
"profile_background_color" = C0DEED;
"profile_background_image_url" = "http://a3.twimg.com/a/1304019356/images/themes/theme1/bg.png";
"profile_background_tile" = false;
"profile_image_url" = "http://a0.twimg.com/profile_images/1190671091/ProfilePhoto_normal.png";
"profile_link_color" = 0084B4;
"profile_sidebar_border_color" = C0DEED;
"profile_sidebar_fill_color" = DDEEF6;
"profile_text_color" = 333333;
"profile_use_background_image" = true;
protected = 0;
"screen_name" = zad0xs1s;
"show_all_inline_media" = true;
"source_api_request_type" = 12;
status = {
contributors = "";
coordinates = "";
"created_at" = "Sat May 07 07:42:18 +0000 2011";
favorited = false;
geo = "";
id = 66769811828514816;
"in_reply_to_screen_name" = zad0xs1s;
"in_reply_to_status_id" = "";
"in_reply_to_user_id" = 191964939;
place = "";
"retweet_count" = 0;
retweeted = false;
source = "BirdieApp";
"source_api_request_type" = 12;
text = "#zad0xs1s sdjdjdd";
truncated = 0;
};
"statuses_count" = 16;
"time_zone" = Madrid;
url = "http://www.pabloxweb.es";
"utc_offset" = 3600;
verified = false;
}
I think it's JSON, but not sure. I also tried with the url twitter gives but didn't got to work too. The URL is http://api.twitter.com/1/users/show.json?screen_name=zad0xsis , where "zad0xsis" is the twitter username.
Thanks in advance!! ;)
Hii.
Here is a good link OAuth Twitter
This example uses model to get json result in NSDictionary .They called getUsertimeLine method . You can call your own method.
My experience with Cocoa & JSON is
It just won't work right...
or It's not worth all of the trouble to parse it!
You might be better off using the Twitter XML API
https://api.twitter.com/1/users/show.xml?screen_name=zad0xsis
Then using NSXMLParser to parse it (on iPhone): http://ll.io/e17
or
NSXMLDocument (Mac): http://ll.io/ff0
Hope this helps!