我正在尝试获取google plus中的所有人员列表并且它可以正常工作,但问题是它仅适用于已登录的用户,如果用户尝试重新登录,表格不会重新加载我需要再次返回并再次点击G +好友按钮来加载数据。我注意到,如果用户会话状态未经过身份验证,当他点击G + friends按钮时,系统会提示登录,并且会调用我的SignupViewController中的回调函数(finishedWithAuth)。所以我所做的是为我的FrienListViewController创建了一个对象,它显示了朋友列表并在G +回调函数中调用了它的viewdidLoad方法,每个函数似乎都被调用了,在NSLog上我也得到了人员列表和图像但是表格根本没有重新加载,当调用viewDidLoad 时它没有调用任何tableview方法,我做了一些搜索,试图实现NSNotification Center,但是选择器方法永远不会被调用。 可能是我以错误的方式实施它。您可以检查我的代码并帮助我解决任何合适的方法吗?
SignupViewController.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(@“Table Delegate:%@”,friendsTable.delegate);在开始时返回Friendviewcontroller,但是当从G +回调函数调用视图didload时返回null,这是主要问题。有什么建议吗?
答案 0 :(得分:0)
试试这个........
if([Reusables getDefaultValue:@"fetchGoogleFriends"])
{
FriendListViewController *ob= (FriendListViewController*)[self.navigationController topViewController];
[ob viewDidLoad];
[ob.friendsTable reloadData];
}