您好我使用以下代码在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。如何确保用户在应用程序打开时自动登录,除非他们不注销。谢谢。
答案 0 :(得分:1)
当您在CustomerToken
中存储NSUserDefault
时,在didFinishLaunchingWithOptions
中检查CustomerToken
的值,如果有任何值,则导航用户进入主屏幕它没有任何价值,然后将用户导航到您的登录屏幕。
另外,请确保在注销时清除NSUserDefault