iOS Buy SDK
The iOS Buy SDK provides a typed Swift interface to the Storefront API. Use it to fetch products, manage carts, and produce a checkoutUrl you can hand to Checkout Kit.
Anchor to What the Buy SDK doesWhat the Buy SDK does
The Buy SDK wraps the Storefront API in typed Swift methods. Each capability has a recommended alternative:
| Task | Buy SDK | Alternative |
|---|---|---|
| Fetch products and collections | Yes (typed Swift interface) | Direct Storefront API calls |
| Create and manage carts | Yes (typed Swift interface) | Direct Storefront API calls |
| Present checkout | No (use Checkout Kit) | Checkout Kit |
Anchor to RequirementsRequirements
- iOS 13.0 or higher.
- Xcode 14.0 or higher.
- Swift 5.7 or higher.
- A Storefront API access token.
Anchor to Step 1: Generate an access tokenStep 1: Generate an access token
To generate an access token, you can generate one in the Shopify admin. Alternatively, you can create a custom app and use authorization code grant.
Anchor to Step 2: Make your products and collections availableStep 2: Make your products and collections available
After you've generated an access token, you need to make products and collections available to your custom app to access them from your app. After the products and collections are available, you can retrieve them using their respective IDs.
If you have many products or collections, then you can use bulk actions to make them available in one step.
If you have many products or collections, then you can use bulk actions to make them available in one step.
Anchor to Make a product availableMake a product available
- From your Shopify admin, go to Products.
- From the Products page, click the product you want to make available.
- Next to SALES CHANNELS AND APPS click Manage.
- In the Sales channels and apps dialog box, select the box next to the name of your custom app.
Anchor to Make a collection availableMake a collection available
- From your Shopify admin, go to Products and click Collections.
- From the Collections page, click the collection you want to make available.
- Next to SALES CHANNELS AND APPS click Manage.
- In the Sales channels and apps dialog box, select the box next to the name of your custom app.
Anchor to Step 3: Install the SDKStep 3: Install the SDK
Add the Buy SDK to your project using Swift Package Manager:
Package.swift
Or in Xcode: File > Add Package Dependencies and enter https://github.com/Shopify/mobile-buy-sdk-ios.
Anchor to Step 4: Initialize the clientStep 4: Initialize the client
Create a client instance with your shop domain and Storefront API access token:
Swift
Anchor to Step 5: Fetch productsStep 5: Fetch products
Query the Storefront API to get products. Save the variant ID for creating a cart:
Swift
Anchor to Step 6: Create a cartStep 6: Create a cart
Use the variant ID to create a cart and get a checkoutUrl:
Swift
Anchor to Step 7: Present checkout with Checkout KitStep 7: Present checkout with Checkout Kit
With the checkoutUrl from the cart, use Checkout Kit to present checkout:
Swift
See Embed Checkout Kit for complete checkout setup.
Anchor to Configure universal links (optional)Configure universal links (optional)
Set up universal links to integrate your app with Safari. When a buyer taps a link to your website, then your app opens if they have it installed.
Your online store automatically hosts the Apple app site association file at /.well-known/apple-app-site-association.
Your online store automatically hosts the Apple app site association file at /.well-known/apple-app-site-association.
- From your Shopify admin, go to Apps.
- Click Develop apps.
- Click the name of your app.
- Click API Integrations.
- In the Storefront API integration section, click Configure.
- Expand the iOS Buy SDK configuration section.
- Enter your Apple App ID.
- Select Use iOS universal links.
Anchor to Next stepsNext steps
Anchor to Where to get helpWhere to get help
Shopify support covers issues with the iOS Buy SDK itself, but not general mobile app development. Here's how to get help:
Find a Shopify Partner for hire in our ecosystem of talented development agencies.
Ask questions and share knowledge with other Shopify developers.
Report bugs or request features for the iOS Buy SDK.