Question

I'm trying to fetch all the people list in google plus and it works but the problem is that it works fine only for a already logged in user, if a user attempts a fresh login the table doesnt get reloaded I need to go back and click on the G+ friends button again to load the data. I've noticed that if the user session status is not authenticated and when he clicks on the G+ friends button he is prompted with login and the call back function (finishedWithAuth) which is in my SignupViewController gets called. So what I did was created an object for my FrienListViewController which displays the friend list and call its viewdidLoad method in the G+ call back function, every function seems to get called and on NSLog I'm also getting the people list and images but the table doesnt get reloaded at all, it doesnt call any tableview methods when the call is made from viewDidLoad, I did some search and tried to implement the NSNotification Center, but the selector method never gets called. May be I'm implementing it in wrong way. Can you check my code and help me with any suitable workaround?

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];
}

These are some other important function for fetching friends, look this if u cant able to figure out error in previous methods

-(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); returns Friendviewcontroller in beginning but returns null when the view didload is called from the G+ callback function, this is the main problem. Any suggestions ?

Was it helpful?

Solution

Try this........

 if([Reusables getDefaultValue:@"fetchGoogleFriends"])
    {

    FriendListViewController *ob= (FriendListViewController*)[self.navigationController topViewController];
    [ob viewDidLoad];
    [ob.friendsTable reloadData];


    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top