如何保持用户login或检查用户是否login或不在Shopify?

您好,我使用下面的代码在Shopify中login用户。

NSArray *items = @[[BUYAccountCredentialItem itemWithEmail:email], [BUYAccountCredentialItem itemWithPassword:password]]; BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items]; [self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer * customer, BUYCustomerToken * token, NSError * _Nullable error) { if (customer && !error) { NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; [prefs setObject:token.accessToken forKey:@"CustomerToken"]; [prefs setInteger:[token.customerID integerValue] forKey:@"CustomerId"]; [prefs synchronize]; NSLog(@"Success fully loged in token %@ %@",token.accessToken,token.customerID); UINavigationController *navigationController = self.navigationController; [navigationController popViewControllerAnimated:YES]; }else{ [self showEror:@"LogIn Failed" message:@"Please provide valid Details"]; } }]; 

每次我必须login并继续进行。 我在本地存储令牌和customerId。 如何确保用户在应用程序打开时自动login,除非他们不注销。 谢谢。

当您在NSUserDefault中存储CustomerToken时,在didFinishLaunchingWithOptions检查CustomerToken的值(如果有任何值),将用户导航到主屏幕(如果没有任何值),然后将用户导航到login屏幕。

此外,请确保在注销时,您将清除NSUserDefault的值