gpt4 book ai didi

ios - FBFriendPickerViewController 在 iOS 上显示和空表。 Place Picker 运行良好

转载 作者:行者123 更新时间:2023-11-29 10:43:02 25 4
gpt4 key购买 nike

我有这段代码,是从 FB 样本复制而来的(它运行良好),但在我的应用程序中只显示了一个用于好友选择器的空白表格。 Place Picker 运行良好,显示了一张完整的表格。

Friend Picker 有什么问题?

在 AppDelegate 中:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[FBFriendPickerViewController class];
[FBPlacePickerViewController class];

return YES;
}

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}

在 View Controller 中:

- (IBAction)pickFriendsButtonClick:(id)sender {
// FBSample logic
// if the session is open, then load the data for our view controller
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
} else if (session.isOpen) {
[self pickFriendsButtonClick:sender];
}
}];
return;
}
// Create friend picker, and get data loaded into it.
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = @"Pick Friends";
friendPickerController.delegate = self;

[friendPickerController loadData];

[friendPickerController presentModallyFromViewController:self animated:YES handler:nil];
}
- (IBAction)pickPlacesButtonClick:(id)sender{
// FBSample logic
// if the session is open, then load the data for our view controller
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
} else if (session.isOpen) {
[self pickPlacesButtonClick:sender];
}
}];
return;
}
// Initialize the place picker
FBPlacePickerViewController *placePickerController = [[FBPlacePickerViewController alloc] init];
// Set the place picker title
placePickerController.title = @"Pick Place";
// Hard code current location to Menlo Park, CA
placePickerController.locationCoordinate = CLLocationCoordinate2DMake(37.453827, -122.182187);
// Configure the additional search parameters
placePickerController.radiusInMeters = 1000;
placePickerController.resultsLimit = 50;
placePickerController.searchText = @"restaurant";
placePickerController.delegate = self;

// Load the place data
[placePickerController loadData];
// Show the place picker modally
[placePickerController presentModallyFromViewController:self animated:YES handler:nil];
}

- (void)facebookViewControllerDoneWasPressed:(id)sender {
NSLog(@"Done pressed");
[self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)facebookViewControllerCancelWasPressed:(id)sender {
NSLog(@"Cancel pressed");
[self dismissViewControllerAnimated:YES completion:NULL];
}

项目:

  1. 制作了一个只有单一 View 的全新项目。
  2. 添加了 2 个按钮并将它们与操作相关联。
  3. 复制/粘贴示例中的代码。
  4. 添加 Facebook 框架。
  5. 编辑 plist 文件以添加 Facebook 申请编号。

我的餐 table (Place Picker) 满了餐厅。我的表( friend 选择器)仍然是空的。我做错了什么?

最佳答案

第 1 步:如果不存在则打开 Facebook session

if ( !FBSession.activeSession.isOpen ) {
[FBSession openActiveSessionWithPermissions:@[@"public_profile", @"email", @"user_friends" ]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}

第 2 步:请求获取好友列表(包括必填字段)

FBRequest* friendsRequest = [FBRequest requestWithGraphPath:@"me/friends?fields=picture,name,username,location,first_name,last_name" parameters:nil HTTPMethod:@"GET"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary* result, NSError *error) {
//store result into facebookFriendsArray
self.facebookFriendsArray = [result objectForKey:@"data"];
}];

第 3 步:从 facebookFriendsArray 重新加载数据到 tableView

关于ios - FBFriendPickerViewController 在 iOS 上显示和空表。 Place Picker 运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23530707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com