开发者

Facebook graph api data inconsistent application data IOS

In my app i'm using a users feeds to retrieve al the post done by my app. I simply retrieve al the posts, and the compare on every post the id number of the app.

This work ok. But i've found a bug in this method. Since the application node isn't always consistent. Normally when there is a post which is not done by a开发者_JAVA百科n app, the entry in the dictionary just says (null), there isn't any data. This doesn't give any problems.

But there is an app which has other data in the this application node. This one has data in this node which specifically says (note the difference between () and <> ). But I can't seem any way to check if the dictionary with that post has in it. i've tried the following:

NSDictionary *resultPost1 =[resultPost objectForKey:@"application"];
            NSLog(@"result%@", [resultPost objectForKey:@"application"]);
            if ([resultPost1 count] != 0) {

This one gives a sigabrt, with the following nslog before the sigabrt:

result(null)

result{ id = 1957711133323244365557378; name = "app"; }

result< null > (added space for visibility)

I've also tried isEqualtoString:@"< null>" Also without success.

It looks like sometimes, their is an dictionary in the application node, and sometimes a string .

Anyone has clue??? Thanks!!!


You will have to do some checking as you don't have a guarantee as to what sort of object is returned from the dictionary.

NSDictionary *resultPost1 = [resultPost objectForKey:@"application"];
if ([[resultPost1 class] isKindOfClass:[NSDictionary class]) {
  //Treat as a dictionary
}
else if ([[resultPost1 class] isKindOfClass:[NSString class]) {
  //Treat as a string
}
else if ([resultPost1 isEqual:[NSNull null] || !resultPost) {
  //Treat as Null, note the json library Facebook uses might set
  //a json NULL into a NSNull object instead of nil
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜