找不到FBRequestConnection类方法

时间:2012-09-03 03:56:10

标签: objective-c facebook facebook-fql facebook-ios-sdk

我正在尝试按照Facebook Facebook developer's site上的教程指示为Facebook运行Facebook多查询,下面是我在iOS应用中的代码:

-(BOOL) FBGetFriendList
{
    if (FBSession.activeSession.isOpen)
    {
        // Multi-query to fetch the active user's friends
        // Initial query is stored in reference named "friends"
        // Second query picks up the "uid2" info from the first query
        // and gets the friend details.
        NSString *query = 
        @"{"
        @"'friends':'SELECT uid2 FROM friend WHERE uid1 = me()',"
        @"'friendinfo':'SELECT uid, name, pic_square FROM user WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM #friends)',"
        @"}";

        // Setup the query parameter
        NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];

        // Make the API request that uses FQL
        [FBRequestConnection startWithGraphPath:@"/fql"
                                 parameters:queryParam
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *_connection, id _result, NSError *_error) {
            // check for errors here
            if (_error)
            {
                NSLog(@"FacebookSDKPlugin > FBGetFriendList() > request error!");
            }
            else
            {
                @synchronized(friendList)
                {
                    if (friendList == nil)
                    {
                        friendList = [[NSMutableArray alloc] init];
                    }
                    else
                    {
                        [friendList removeAllObjects];
                    }
                    NSArray *facebookData = [(NSDictionary *)_result objectForKey:@"data"];
                    int count = facebookData.count;
                    for (int i = 0; i < count; ++i)
                    {
                        NSDictionary<FBGraphUser> *tempObject = [facebookData objectAtIndex:i];
                        FacebookFriend *tempFriend = [[FacebookFriend alloc] initWithID:[tempObject.id copy] name:[tempObject.name copy]];
                        [friendList addObject:tempFriend];
                    }
                }
             }
        }];
        return YES;
    }
    return NO;
}

但是,在编译期间会出现警告:

Class method '+startWithGraphPath:parameters:HTTPMethod:completionHandler:' not found (return type defaults to 'id')

我忽略了错误,并在我的iPad2上编译,因为这个错误崩溃了:

2012-09-03 11:53:13.377 +[FBRequestConnection startWithGraphPath:parameters:HTTPMethod:completionHandler:]: unrecognized selector sent to class 0xa05350
2012-09-03 11:53:13.379 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBRequestConnection startWithGraphPath:parameters:HTTPMethod:completionHandler:]: unrecognized selector sent to class 0xa05350'

我已经包含了“FBRequest.h”和“Facebook.h”,我可以在“FBRequest.h”中看到该方法。但是我不明白为什么编译器找不到该函数。有没有人知道如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Opps我意识到我一直在使用旧版本的FacebookSDK,这解释了为什么代码不能像官方教程中所说的那样工作。更新到最新版本的SDK(版本3.0.8)修复了此问题!