0
嗨我使用以下代碼在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"];
}
}];
每次我必須登錄並繼續進一步操作。我在本地存儲令牌和customerId。如何確保用戶在應用程序打開時自動登錄,除非他們不註銷。謝謝。
的NSLog(@ 「Customeer令牌%@」,self.client.customerToken.accessToken)清除值;它顯示爲空。那麼我怎麼能夠將產品添加到客戶的購物車?關閉應用程序時我沒有註銷。 –
什麼時候顯示null? – Rajat
初始化BUYClient後。但是一旦我登錄並且登錄意味着它顯示正確的標記。 –