Mobile Buy SDK for iOS
Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
Documentation
Please find all documentation on the Mobile Buy SDK for iOS page.
Installation
Manual Installation (Project)
- Drag the
Mobile Buy SDK.xcodeproj
into your existing project - Add the
Buy
target as aTarget Dependancy
in theBuild Phases
of your project's target - Add the
Buy
target in theLink Binary with Libraries
section inBuild Phases
Manual Installation (Framework)
If you would like to not include the Mobile Buy SDK Project within your existing project, you can link directly to the Buy.framework
.
- Open the
Mobile Buy SDK.xcodeproj
and build theUniversal Framework
Target - Drag the
Buy.framework
that was just created fromMobile Buy SDK Sample Apps
onto theLinked Frameworks and Libraries
section for the target you want to add the framework to. Check Copy items if needed so the framework is copied to your project - In the
Build Settings
tab, add-all_load
toOther Linker Flags
.
CocoaPods
Add the following line to your podfile:
pod "Mobile-Buy-SDK"
Then run pod install
Carthage
Add the following line to your Cartfile
github "Shopify/mobile-buy-sdk-ios"
Then run carthage update
Quick Start
Import the module
@import Buy;
Initialize the BUYClient
with your credentials from the Mobile App Channel
BUYClient *client = [[BUYClient alloc] initWithShopDomain:@"yourshop.myshopify.com"
apiKey:@"aaaaaaaaaaaaaaaaaa"
channelId:@"99999"];
// Fetch your products
[self.client getProductsPage:1 completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) {
if (error) {
NSLog(@"Error retrieving products: %@", error.userInfo);
} else {
for (BUYProduct *product in products) {
NSLog(@"%@", product.title);
}
}
}];
Consult the Usage Section of the Integration Guide on how to create a cart, and checkout with the SDK.
Building the SDK
Clone this repo or download as .zip and open Mobile Buy SDK.xcworkspace
.
The workspace includes the Mobile Buy SDK project and the sample app projects. The sample apps can also be opened outside the workspace with the .xcodeproj
files found in the sample app folders. However, if you need to use breakpoints or inspect methods in the SDK, run the sample apps from the workspace.
Mobile Buy SDK Targets and schemes
The Mobile Buy SDK includes a number of targets and schemes:
Buy: This is the Mobile Buy SDK framework. This build is based on the current build configuration. To build a universal framework that can run on a device and on the Simulator and to be included in your app, please refer to the
Universal Framework
target belowUniversal Framework: This builds the framework using
build_universal.sh
script in theUniversal Framework
target and copies the built framework in the/Mobile Buy SDK Sample Apps
folder. Build this target if you have made any changes to the framework that you want to test with the sample apps as the sample apps do not build the framework directly but embed the already built frameworkMobile Buy SDK Tests: Tests for the Mobile Buy SDK framework. See instructions below
Documentation: This generates appledoc documentation for the framework
Playground: This target is a basic app that depends directly on the
Buy
framework target and builds the framework every time using thePlayground
app's build configuration. You may use this app and target to play around with the SDK. Be sure not to check in any changes you may have made in files related to this app
Unit Tests
To run the Mobile Buy SDK integration tests against an actual shop, you will need a Shopify shop that is publicly accessible (not password protected). Please note that the integration tests will create an order on that shop. This is to validate that the SDK works properly with Shopify. Modify the test_shop_data.json file to contain your shop's credentials and the required product IDs, gift cards, and discounts as necessary.
If the credentials in the test_shop_data.json are empty, running the integration tests will use using mocked respoonses. The mocked responses are defined in mocked_responses.json. Do not check in credentials in this file.
Alternatively, you can edit the Mobile Buy SDK Tests
scheme and add the following arguments to the Environment Variables:
-
shop_domain
: Your shop's domain, for example:abetterlookingshop.myshopify.com
-
api_key
: The API provided when setting up the Mobile App channel on Shopify Admin: https://your_shop_id.myshopify.com/admin/mobile_app/integration -
channel_id
: The Channel ID provided with the API Key above -
gift_card_code_11
,gift_card_code_25
,gift_card_code_50
: Three valid Gift Card codes for your shop -
expired_gift_card_code
: An expired Gift Card code -
expired_gift_card_id
: The ID for the expired Gift Card -
product_ids_comma_separated
: a comma seperated list of product IDs (2 is suitable) to use for the cart
How Can I Contribute?
We welcome contributions. Follow the steps in CONTRIBUTING file
License
The Mobile Buy SDK is provided under an MIT Licence. See the LICENSE file