Commit a79a3661 by David Muzi Committed by GitHub

Merge pull request #254 from Shopify/task/swift-app-fix

Fix Swift Sample App
parents ad1eef50 46c21deb
......@@ -7,13 +7,12 @@
objects = {
/* Begin PBXBuildFile section */
BE3437BB1BC5C22C00C71330 /* Buy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE3437B81BC5C20700C71330 /* Buy.framework */; };
BE3437BC1BC5C22C00C71330 /* Buy.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BE3437B81BC5C20700C71330 /* Buy.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
BE9A637A1B5007AA0033E558 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE9A63791B5007AA0033E558 /* AppDelegate.swift */; };
BE9A637C1B5007AA0033E558 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE9A637B1B5007AA0033E558 /* ViewController.swift */; };
BE9A637F1B5007AA0033E558 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BE9A637D1B5007AA0033E558 /* Main.storyboard */; };
BE9A63811B5007AA0033E558 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BE9A63801B5007AA0033E558 /* Images.xcassets */; };
BE9A63841B5007AA0033E558 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = BE9A63821B5007AA0033E558 /* LaunchScreen.xib */; };
BEDEFF541D3823180090AFA1 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEDEFF531D3823180090AFA1 /* Config.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -31,13 +30,6 @@
remoteGlobalIDString = BE9A64281B503C2F0033E558;
remoteInfo = Buy;
};
BE3437B71BC5C20700C71330 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = BE3437A81BC5C20700C71330 /* Mobile Buy SDK.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 901931701BC5B9BC00D1134E;
remoteInfo = "Buy Dynamic";
};
BE3437B91BC5C21300C71330 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = BE3437A81BC5C20700C71330 /* Mobile Buy SDK.xcodeproj */;
......@@ -61,7 +53,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
BE3437BC1BC5C22C00C71330 /* Buy.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -77,6 +68,7 @@
BE9A637E1B5007AA0033E558 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
BE9A63801B5007AA0033E558 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
BE9A63831B5007AA0033E558 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
BEDEFF531D3823180090AFA1 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -84,7 +76,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
BE3437BB1BC5C22C00C71330 /* Buy.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -94,9 +85,8 @@
BE3437A91BC5C20700C71330 /* Products */ = {
isa = PBXGroup;
children = (
BE3437B41BC5C20700C71330 /* Mobile Buy SDK Tests.xctest */,
BE3437B61BC5C20700C71330 /* Buy.framework */,
BE3437B81BC5C20700C71330 /* Buy.framework */,
BE3437B41BC5C20700C71330 /* Mobile Buy SDK Tests.xctest */,
);
name = Products;
sourceTree = "<group>";
......@@ -123,6 +113,7 @@
children = (
BE9A63791B5007AA0033E558 /* AppDelegate.swift */,
BE9A637B1B5007AA0033E558 /* ViewController.swift */,
BEDEFF531D3823180090AFA1 /* Config.swift */,
BE9A637D1B5007AA0033E558 /* Main.storyboard */,
BE9A63801B5007AA0033E558 /* Images.xcassets */,
BE9A63821B5007AA0033E558 /* LaunchScreen.xib */,
......@@ -216,13 +207,6 @@
remoteRef = BE3437B51BC5C20700C71330 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
BE3437B81BC5C20700C71330 /* Buy.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = Buy.framework;
remoteRef = BE3437B71BC5C20700C71330 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */
......@@ -245,6 +229,7 @@
files = (
BE9A637C1B5007AA0033E558 /* ViewController.swift in Sources */,
BE9A637A1B5007AA0033E558 /* AppDelegate.swift in Sources */,
BEDEFF541D3823180090AFA1 /* Config.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
//
// Config.swift
// Mobile Buy SDK Swift Sample
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import Foundation
struct Config {
static let shopDomain = ""
static let apiKey = ""
static let appId = ""
static let productId = ""
}
......@@ -29,63 +29,50 @@ import Buy
class ViewController: UIViewController {
@IBOutlet var titleLabel: UILabel!
@IBOutlet var imageView: UIImageView!
let shopDomain = ""
let apiKey = ""
let channelId = ""
let productId = ""
let modelManager = BUYModelManager()
@IBOutlet private var titleLabel: UILabel!
@IBOutlet private var imageView: UIImageView!
var productVariant: BUYProductVariant?
let client: BUYClient
required init(coder aDecoder: NSCoder) {
client = BUYClient(shopDomain: shopDomain, apiKey: apiKey, appId: appId)
client = BUYClient(shopDomain: Config.shopDomain, apiKey: Config.apiKey, appId: Config.appId)
super.init(coder: aDecoder)!
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
client.getProductById(productId) { (product, error) -> Void in
client.getProductById(Config.productId) { (product, error) in
self.titleLabel.text = product?.title
self.productVariant = product?.variants.objectAtIndex(0) as! BUYProductVariant?
guard let product = product else { return }
if (product != nil && error == nil) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let images = product?.images
let buyImage = images?.firstObject as! BUYImageLink
let url = NSURL(string: buyImage.src!)
let data = NSData(contentsOfURL: url!)
let image = UIImage(data: data!)
dispatch_async(dispatch_get_main_queue()) {
self.imageView.image = image
}
self.titleLabel.text = product.title
self.productVariant = product.variantsArray().first
guard let buyImage = product.images?.firstObject as? BUYImageLink else { return }
NSURLSession.sharedSession().dataTaskWithURL(buyImage.sourceURL) { (data, response, error) in
guard let data = data else { return }
dispatch_async(dispatch_get_main_queue()) {
let image = UIImage(data: data)
self.imageView.image = image
}
}
}.resume()
}
}
@IBAction func didTapCheckout(sender: UIButton) {
// Create the checkout
let cart = modelManager.buy_objectWithEntityName(BUYCart.entityName(), JSONDictionary: nil) as! BUYCart
let cart = client.modelManager.buy_objectWithEntityName(BUYCart.entityName(), JSONDictionary: nil) as! BUYCart
cart.addVariant(productVariant!)
let checkout = BUYCheckout(cart: cart)
let checkout = client.modelManager.checkoutWithCart(cart)
client.createCheckout(checkout) { (checkout, error) -> Void in
if let checkoutURL = checkout?.webCheckoutURL {
......@@ -94,7 +81,6 @@ class ViewController: UIViewController {
}
}
}
}
}
......@@ -4,12 +4,12 @@ The Swift sample app demonstrates how to use the SDK within a Swift app. The app
### Getting started
First, add your shop domain, API key and Channel ID to the `ViewController.swift`.
First, add your shop domain, API key and App ID to the `Config.swift`.
```swift
let shopDomain = ""
let apiKey = ""
let channelId = ""
let appId = ""
let productId = ""
```
......
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