如何让用户登录或检查用户是否在Shopify中登录?

时间:2016-12-01 08:33:54

标签: ios objective-c 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。如何确保用户在应用程序打开时自动登录,除非他们不注销。谢谢。

1 个答案:

答案 0 :(得分:1)

当您在CustomerToken中存储NSUserDefault时,在didFinishLaunchingWithOptions中检查CustomerToken的值,如果有任何值,则导航用户进入主屏幕它没有任何价值,然后将用户导航到您的登录屏幕。

另外,请确保在注销时清除NSUserDefault

中的值