iOS Shopify中的登录/注册API实施 [英] Login/Signup API implementation in iOS Shopify

查看:238
本文介绍了iOS Shopify中的登录/注册API实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用shopify SDK开发移动应用程序,但是我找不到能够在我的应用程序中实现登录/注册的任何内容.我已经完成购物车/产品的购买,但是无法实现客户登录.是否有任何解决方案可以在应用程序中使用Shopify来实现登录/注册,或者我可以在shopify和自定义PHP服务之间建立桥梁?

I am developing an Mobile app using shopify SDK, however I am not able to find anything to implement Login/Signup into my app. I have done shopping cart/products but unable to implement customer login. Is there any solution to implement login/signup using Shopify in app or any bridge I can create between shopify and custom PHP services.

谢谢.

推荐答案

您可以使用教程中提供的Shopify API,我提供了用于登录和注册的代码.

You can use Shopify API which is given in tutorial, I have give code for Login and Sign up.

登录代码

 NSArray *credentialItems = @[
                             [BUYAccountCredentialItem itemWithEmail:self.txtEmailID.text],
                             [BUYAccountCredentialItem itemWithPassword:self.txtPassword.text],
                             ];
 BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:credentialItems];

[self.aClient loginCustomerWithCredentials:credentials callback:^(BUYCustomer * _Nullable customer, BUYCustomerToken * _Nullable token, NSError * _Nullable error) {

    if (customer && token && !error) {

        NSLog(@"Login Done");

    } else {
        //NSLog(@"Failed to login customer: %@", error.userInfo);
        _lblMessage.text=error.localizedDescription;
    }
}];

注册代码

NSArray *credentialItems = @[
                             [BUYAccountCredentialItem itemWithFirstName:self.txtFirstName.text],
                             [BUYAccountCredentialItem itemWithLastName:self.txtLastName.text],
                             [BUYAccountCredentialItem itemWithEmail:self.txtEmailID.text],
                             [BUYAccountCredentialItem itemWithPassword:self.txtPassword.text]
                             ];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:credentialItems];

[client createCustomerWithCredentials:credentials callback:^(BUYCustomer * _Nullable customer, BUYCustomerToken * _Nullable token, NSError * _Nullable error) {

    if (customer && token && !error) {

        self.txtFirstName.text =@"";
        self.txtLastName.text = @"";
        self.txtEmailID.text=@"";
        self.txtPassword.text=@"";

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Shopify" message:@"Signup successfully" preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
        [alertController addAction:okAction];
        [self presentViewController:alertController animated:YES completion:nil];
    }
    else
    {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Shopify" message:error.localizedDescription preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
        [alertController addAction:okAction];
        [self presentViewController:alertController animated:YES completion:nil];

        //NSLog(@"Failed to create customer: %@", error.userInfo);
    }

    }];

这篇关于iOS Shopify中的登录/注册API实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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