如何保持用户登录或检查用户是否登录Shopify? [英] How to keep the user logged in or check if the user is logged in or not in Shopify?

查看:54
本文介绍了如何保持用户登录或检查用户是否登录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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆