Start a new topic

User session is not stored after 24 hours .

Hi

 I am using IOS SDK 1.40.8 and have next issue 


1) Logging to my app by Facebook SDK 

2) Close it 

3) Open it on a next day 

4) My app ask  me to login again. Looks like user session is expired.


How can store the logged user session?





Wood,

By any chance, are you logging out of Facebook anywhere in the app? or logging out of the facebook app itself?

Thanks,
Pranav
Kinvey Support

 

Pranav


No. I just close my app without logging out Facebook and after some time open app. And [KCSUser activeUser] equals nil. I will try last version of Facebook SDK and late youy know 

Best Regards

Alex

Pranav 

I reproduced it again on Facebook SDK v4.15.0. Session is not storred after 1 hour 

Wood,

Please refer to these steps:
http://devcenter.kinvey.com/ios/guides/users#facebook

Can you let me know if you are getting any error in the completion block of login?
[KCSUser loginWithSocialIdentity:accessDictionary:withCompletionBlock:]

Also how are you retrieving the access token that is passed to the above login function?
(KCSUserAccessTokenKey : accessToken)

 

Thanks,

Pranav

Kinvey Support

Pranav


1) What I received


2016-09-09 08:59:30.385684 BooksAround[483:35646] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles

2016-09-09 08:59:30.387291 BooksAround[483:35646] [MC] Reading from public effective user settings.

2016-09-09 08:59:56.471265 BooksAround[483:35708] [LogMessageLogging] 6.1 <private>


2) I didn't received access token if I logged in by Facebook. I thought Kinvey will work like " email login " case.

So I should get accessToken and login by loginWithSocialIdentity , am I right ?


Wood,

Can you please share your relevant code, so that I can take a look at it and also try out the issue?

Thanks,
Pranav
Kinvey Support

 

 

#import "LoginViewController.h"



@interface LoginViewController()  <CLLocationManagerDelegate>
{
    CLLocationManager *manager;
    __block NSString *userId;
    id withLibrary ;
}
@property (nonatomic, strong) KCSLinkedAppdataStore * store ;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [_emailTextField setDelegate:self];
    [_passwordTextField setDelegate:self];
    manager = [[CLLocationManager alloc] init];
    [manager requestWhenInUseAuthorization];
    [self.navigationController setNavigationBarHidden:YES];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // Имя вашей storyboard, обычно так и есть - MainStoryboard.
    CreateLibraryViewController *testViewController = (CreateLibraryViewController *)
    [storyboard  instantiateViewControllerWithIdentifier:@"CreateLibraryView"];
    withLibrary = [[KCSUser activeUser] getValueForAttribute:@"withLibrary"];
    
    if([KCSUser activeUser]){
       
      if ([withLibrary boolValue]== YES){
          CreateLibraryViewController *testViewController = (CreateLibraryViewController *)[storyboard  instantiateViewControllerWithIdentifier:@"MainTabBar"];
          [self.navigationController pushViewController:testViewController animated:NO];
            } else {
                [self.navigationController pushViewController:testViewController animated:NO];
                         }
           }
    
}



- (IBAction)signupWithFacebookButtonPressed:(UIButton *)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // Имя вашей storyboard, обычно так и есть - MainStoryboard.
    CreateLibraryViewController *testViewController = (CreateLibraryViewController *)[storyboard instantiateViewControllerWithIdentifier:@"CreateLibraryView"]; // identifier вам нужно, чтобы был проставлен в Storyboard.
    
    NSArray *permissionsArray = @[ @"public_profile"];
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
  // login.loginBehavior = FBSDKLoginBehaviorWeb;
     login.loginBehavior = FBSDKLoginBehaviorSystemAccount;
    [login logInWithReadPermissions: permissionsArray fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            NSLog(@"Process error");
        } else if (result.isCancelled) {
            NSLog(@"Cancelled");
        } else {
            
            if ([FBSDKAccessToken currentAccessToken])
                
            {
                NSString* accessToken = [FBSDKAccessToken currentAccessToken].tokenString;
                [KCSUser loginWithSocialIdentity:KCSSocialIDFacebook accessDictionary:@{KCSUserAccessTokenKey : accessToken} withCompletionBlock:^(KCSUser *user, NSError *errorOrNil, KCSUserActionResult result) {
                    
                    
                    if  ( ([user.givenName length] == 0) && ([user.surname length] == 0)){
                        
                        NSMutableDictionary* parameters = [NSMutableDictionary dictionary];
                        [parameters setValue:@"id,first_name,last_name,gender" forKey:@"fields"];
                        FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:parameters];
                        [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                            if (!error) {
                                NSDictionary *userData = (NSDictionary *)result;
                                NSURL * newim= [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1",userData[@"id"]]];
                                

                                user.givenName = userData[@"first_name"];
                                user.surname = userData[@"last_name"];
                                [user setValue:userData[@"gender"] forAttribute:@"gender"];
                                [user setValue:newim forAttribute:@"photo"];
                                [user saveWithCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {
                                    if (errorOrNil != nil) {
                                        NSLog(@"an error happened: %@", errorOrNil);
                                    } else {
                                        
                                        [self.navigationController pushViewController:testViewController animated:NO];
                                        
                                    }
                                } ];
                            }
                            
                        }];
                        
                        
                    }
                    else
                    {
                        withLibrary = [[KCSUser activeUser] getValueForAttribute:@"withLibrary"];
                        if ([withLibrary boolValue] == YES){
                            CreateLibraryViewController *testViewController = (CreateLibraryViewController *)[storyboard  instantiateViewControllerWithIdentifier:@"MainTabBar"];
                            [self.navigationController pushViewController:testViewController animated:NO];
                        } else {
                            [self.navigationController pushViewController:testViewController animated:NO];
                        }
                    }

                        
                        
                    }];
                
            }
        }
    }];
}
-

@end

 

any news?

Login or Signup to post a comment