我正在尝试获取 google plus 中的所有人员列表,它可以工作,但问题是它仅适用于已经登录的用户,如果用户尝试重新登录,表不会重新加载我需要返回并再次单击 G+ 好友按钮以加载数据。我注意到,如果用户会话状态未通过身份验证,并且当他单击 G+ 朋友按钮时,系统会提示他登录,并且我的 SignupViewController 中的回调函数 (finishedWithAuth) 会被调用。所以我所做的是为我的 FrienListViewController 创建了一个对象,它显示朋友列表并在 G+ 回调函数中调用其 viewdidLoad 方法,每个函数似乎都被调用了,在 NSLog 上我也得到了人员列表和图像,但是该表根本没有重新加载,当从 viewDidLoad 进行调用时它不会调用任何 tableview 方法,我做了一些搜索并尝试实现 NSNotification Center,但从未调用选择器方法。可能是我以错误的方式实施它。你能检查我的代码并帮助我找到任何合适的解决方法吗?
注册视图控制器.m
//Google Plus callback method
-(void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
{
AppDelegate * appdelegate = [UIApplication sharedApplication].delegate;
[[[GPPSignIn sharedInstance] plusService] executeQuery:[GTLQueryPlus queryForPeopleGetWithUserId:@"me"] completionHandler:^(GTLServiceTicket *ticket, GTLPlusPerson *person, NSError *error)
{
[appdelegate hideLoading];
if(error)
{
NSLog(@"Authentication Error: %@", error);
}
else
{
if([Reusables getDefaultValue:@"fetchGoogleFriends"])
{
FriendListViewController *ob= [[FriendListViewController alloc]init];
[ob viewDidLoad];
[[NSNotificationCenter defaultCenter] postNotificationName:@"MyNotification" object:self];
}
}
}];
}
FriendListViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.friendListSection = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#",nil];
listType=[Reusables getDefaultValue:@"friendListType"];
AppDelegate * appdelegate = [UIApplication sharedApplication].delegate;
[appdelegate showLoading];
[self fetchFriendList];
[self performSelectorInBackground:@selector(fetchPeopleImagesInBackground) withObject:nil];
//[friendsTable reloadData];
[NSNotificationCenter defaultCenter];
NSNotification* notification = [NSNotification notificationWithName:@"MyNotification" object:self];
[[NSNotificationCenter defaultCenter] postNotification:notification];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (objFirstViewController) name:@"MyNotification" object:self];
//This logs returns <Friendviewcontroller> in beginning but returns null when the view didload is called from the G+ callback function, Any suggestions ?
NSLog(@"Table Delegate: %@",friendsTable.delegate);
}
//This method doesnt get called
-(void)objFirstViewController:(NSNotification *)notification
{
[friendsTable reloadData];
}
这些是获取朋友的其他一些重要功能,如果您无法在以前的方法中找出错误,请查看此
-(void)fetchFriendList
{
if ([listType isEqualToString:@"GooglePlus"])
{
if ([GPPSignIn sharedInstance].authentication)
{
NSLog(@"Status is authenticated, fetching friends!!");
[self fetchGooglePlusFriends:kGTLPlusCollectionVisible];
}
else
{
[Reusables storeDataToDefaults:@"fetchGoogleFriends" objectToAdd:@"Enabled"];
[[GPPSignIn sharedInstance]authenticate];
}
}
//Google Plus Fetching friends function
- (void)fetchGooglePlusFriends:(NSString *)collection {
AppDelegate * appdelegate = [UIApplication sharedApplication].delegate;
// 1. Create a |GTLQuery| object to list people that are visible to this
// sample app.
GTLQueryPlus *query =
[GTLQueryPlus queryForPeopleListWithUserId:@"me"
collection:collection];
// 2. Execute the query.
[[[GPPSignIn sharedInstance] plusService] executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusPeopleFeed *peopleFeed,
NSError *error) {
if (error) {
if ([listType isEqualToString:@"GooglePlus"])
{
NSLog(@"Error: %@", error);
[appdelegate hideLoading];
}
} else {
// Get an array of people from |GTLPlusPeopleFeed| and reload
// the table view.
_peopleList = peopleFeed.items;
// Render the status of the Google+ request.
NSNumber *count = peopleFeed.totalItems;
if (count.intValue == 1) {
} else {
NSLog(@"Status: Listed %@ people, listtype:%@, gplusshow:%@", count,listType,[Reusables getDefaultValue:@"fetchGoogleFriends"]);
}
if ([listType isEqualToString:@"GooglePlus"]||[Reusables getDefaultValue:@"fetchGoogleFriends"])
{
[self performSelectorInBackground:@selector(fetchPeopleImagesInBackground) withObject:nil];
[friendsTable reloadData];
[appdelegate hideLoading];
}
}
}];
}
NSLog(@"表委托:%@",friendsTable.delegate); 在开始时返回 Friendviewcontroller 但从 G+ 回调函数调用视图 didload 时返回 null,这是主要问题。有什么建议么 ?