Login/Signup API implementation in iOS Shopify

2019-05-18 14:13发布

问题:

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

    }];