Login/Signup API implementation in iOS Shopify

跟風遠走 提交于 2020-01-13 20:41:05

问题


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.

Thanks.


回答1:


You can use Shopify's customer object from the API.




回答2:


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

Code for Login

 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;
    }
}];

Code for Sign Up

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);
    }

    }];


来源:https://stackoverflow.com/questions/31651027/login-signup-api-implementation-in-ios-shopify

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!