How to keep the user logged in or check if the user is logged in or not in Shopify?(如何保持用户登录或检查用户是否登录Shopify?)
问题描述
您好,我使用以下代码在Shopify中登录了用户。
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"];
}
}];
每次我必须登录并继续操作。我在本地存储了Token和customerId。我如何确保用户在应用程序打开时自动登录,除非他们不注销。谢谢您。
推荐答案
当您在NSUserDefault
中存储CustomerToken
时,请在didFinishLaunchingWithOptions
中检查CustomerToken
的值如果其中有任何值,请将用户导航到您的主屏幕(如果没有任何值),然后将用户导航到您的登录屏幕。
另外,请确保在注销时清除NSUserDefault
这篇关于如何保持用户登录或检查用户是否登录Shopify?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!