iOS Shopify 中的登录/注册 API 实现

问题描述 投票:0回答:2

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

ios authentication shopify
2个回答
0
投票

您可以通过 API 使用 Shopify 的 customer 对象。


0
投票

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

登录密码

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

    }];
© www.soinside.com 2019 - 2024. All rights reserved.