Commit 395d8b2f by Dima Bart

Merge pull request #152 from Shopify/feature/update-readme

Update readme.
parents 9d8671c8 c2d1d259
...@@ -96,20 +96,77 @@ Initialize the `BUYClient` with your credentials from the *Mobile App Channel* ...@@ -96,20 +96,77 @@ Initialize the `BUYClient` with your credentials from the *Mobile App Channel*
BUYClient *client = [[BUYClient alloc] initWithShopDomain:@"yourshop.myshopify.com" BUYClient *client = [[BUYClient alloc] initWithShopDomain:@"yourshop.myshopify.com"
apiKey:@"aaaaaaaaaaaaaaaaaa" apiKey:@"aaaaaaaaaaaaaaaaaa"
channelId:@"99999"]; channelId:@"99999"];
```
### Storefront API
After initializing the client with valid shop credentials, you can begin fetching collections.
```objc
[client getCollections:^(NSArray<BUYCollection *> *collections, NSError *error) {
if (collections && !error) {
// Do something with collections
} else {
NSLog(@"Error fetching collections: %@", error.userInfo);
}
}];
```
Having a collection, we can then retrieve an array of products within that collection:
```objc
BUYCollection *collection = collections.firstObject;
[client getProductsPage:0 inCollection:collection.collectionId completion:^(NSArray<BUYProduct *> *products, NSUInteger page, BOOL reachedEnd, NSError *error) {
if (products && !error) {
// Do something with products
} else {
NSLog(@"Error fetching products in collection %@: %@", collection.collectionId, error.userInfo);
}
}];
```
// Fetch your products ### Customer API
[self.client getProductsPage:1 completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) { ##### Customer Login
if (error) { You can allow customers to login with their existing account using the SDK. First, we'll need to create the `BUYAccountCredentials` object used to pass authentication credentials to the server.
NSLog(@"Error retrieving products: %@", error.userInfo); ```objc
NSArray *credentialItems = @[
[BUYAccountCredentialItem itemWithEmail:@"john.smith@gmail.com"],
[BUYAccountCredentialItem itemWithPassword:@"password"],
];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:credentialItems];
```
We can now use the credentials object to login the customer.
```objc
[client loginCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSString *token, NSError *error) {
if (customer && token && !error) {
// Do something with customer and store token for future requests
} else { } else {
for (BUYProduct *product in products) { NSLog(@"Failed to login customer: %@", error.userInfo);
NSLog(@"%@", product.title);
} }
}];
```
##### Customer Creation
Creating a customer account is very similar to login flow but requres a little more info in the credentials object.
```objc
NSArray *credentialItems = @[
[BUYAccountCredentialItem itemWithFirstName:@"John"],
[BUYAccountCredentialItem itemWithLastName:@"Smith"],
[BUYAccountCredentialItem itemWithEmail:@"john.smith@gmail.com"],
[BUYAccountCredentialItem itemWithPassword:@"password"],
[BUYAccountCredentialItem itemWithPasswordConfirmation:@"password"],
];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:credentialItems];
```
After we obtain the customers first name, last name and password confirmation in addition to the email and password fields, we can create an account.
```objc
[client createCustomerWithCredentials:credentials callback:^(BUYCustomer *customer, NSString *token, NSError *error) {
if (customer && token && !error) {
// Do something with customer and store token for future requests
} else {
NSLog(@"Failed to create customer: %@", error.userInfo);
} }
}]; }];
``` ```
Consult the [Usage Section](https://docs.shopify.com/mobile-buy-sdk/ios/integration-guide/#using-the-mobile-buy-sdk) of the Integration Guide on how to create a cart, and checkout with the SDK. ### Integration Guide
Consult the [Usage Section](https://docs.shopify.com/mobile-buy-sdk/ios/integration-guide/#using-the-mobile-buy-sdk) of the Integration Guide on how to create a cart, checkout and more with the SDK.
### Building the SDK ### Building the SDK
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment