Skip to content

Commit

Permalink
Merge pull request #327 from bizz84/update-iOS-demo-app
Browse files Browse the repository at this point in the history
Update iOS demo app
  • Loading branch information
bizz84 authored Dec 29, 2017
2 parents 72a3493 + 7e76874 commit f4a99d3
Show file tree
Hide file tree
Showing 8 changed files with 531 additions and 235 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ SwiftyStoreKit is a lightweight In App Purchases framework for iOS 8.0+, tvOS 9.

### Preview

<img src="https://github.com/bizz84/SwiftyStoreKit/raw/master/Screenshots/Preview.png" width="320">
<img src="https://github.com/bizz84/SwiftyStoreKit/raw/master/Screenshots/Preview2.png" width="320">
<img src="https://github.com/bizz84/SwiftyStoreKit/raw/master/Screenshots/Preview.jpg" width="320">

### Note from the Author

Expand Down
Binary file added Screenshots/Preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Screenshots/Preview.png
Binary file not shown.
Binary file removed Screenshots/Preview2.png
Binary file not shown.
642 changes: 443 additions & 199 deletions SwiftyStoreKit-iOS-Demo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

95 changes: 74 additions & 21 deletions SwiftyStoreKit-iOS-Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,90 @@ enum RegisteredPurchase: String {
case purchase2
case nonConsumablePurchase
case consumablePurchase
case autoRenewablePurchase
case nonRenewingPurchase
case autoRenewableWeekly
case autoRenewableMonthly
case autoRenewableYearly
}

class ViewController: UIViewController {

let appBundleId = "com.musevisions.iOS.SwiftyStoreKit"

let purchase1Suffix = RegisteredPurchase.purchase1
let purchase2Suffix = RegisteredPurchase.autoRenewablePurchase

// MARK: actions
@IBAction func getInfo1() {
getInfo(purchase1Suffix)

#if os(iOS)
// UISwitch is unavailable on tvOS
@IBOutlet var nonConsumableAtomicSwitch: UISwitch!
@IBOutlet var consumableAtomicSwitch: UISwitch!
@IBOutlet var nonRenewingAtomicSwitch: UISwitch!
@IBOutlet var autoRenewableAtomicSwitch: UISwitch!
var nonConsumableIsAtomic: Bool { return nonConsumableAtomicSwitch.isOn }
var consumableIsAtomic: Bool { return consumableAtomicSwitch.isOn }
var nonRenewingIsAtomic: Bool { return nonRenewingAtomicSwitch.isOn }
var autoRenewableIsAtomic: Bool { return autoRenewableAtomicSwitch.isOn }
#else
let nonConsumableIsAtomic = true
let consumableIsAtomic = true
let nonRenewingIsAtomic = true
let autoRenewableIsAtomic = true
#endif
// MARK: non consumable
@IBAction func nonConsumableGetInfo() {
getInfo(.nonConsumablePurchase)
}
@IBAction func purchase1() {
purchase(purchase1Suffix)
@IBAction func nonConsumablePurchase() {
purchase(.nonConsumablePurchase, atomically: nonConsumableIsAtomic)
}
@IBAction func verifyPurchase1() {
verifyPurchase(purchase1Suffix)
@IBAction func nonConsumableVerifyPurchase() {
verifyPurchase(.nonConsumablePurchase)
}
@IBAction func getInfo2() {
getInfo(purchase2Suffix)

// MARK: consumable
@IBAction func consumableGetInfo() {
getInfo(.consumablePurchase)
}
@IBAction func consumablePurchase() {
purchase(.consumablePurchase, atomically: consumableIsAtomic)
}
@IBAction func consumableVerifyPurchase() {
verifyPurchase(.consumablePurchase)
}

// MARK: non renewing
@IBAction func nonRenewingGetInfo() {
getInfo(.nonRenewingPurchase)
}
@IBAction func purchase2() {
purchase(purchase2Suffix)
@IBAction func nonRenewingPurchase() {
purchase(.nonRenewingPurchase, atomically: nonRenewingIsAtomic)
}
@IBAction func verifyPurchase2() {
verifyPurchase(purchase2Suffix)
@IBAction func nonRenewingVerifyPurchase() {
verifyPurchase(.nonRenewingPurchase)
}

// MARK: auto renewable
#if os(iOS)
@IBOutlet var autoRenewableSubscriptionSegmentedControl: UISegmentedControl!

var autoRenewableSubscription: RegisteredPurchase {
switch autoRenewableSubscriptionSegmentedControl.selectedSegmentIndex {
case 0: return .autoRenewableWeekly
case 1: return .autoRenewableMonthly
case 2: return .autoRenewableYearly
default: return .autoRenewableWeekly
}
}
#else
let autoRenewableSubscription = RegisteredPurchase.autoRenewableWeekly
#endif
@IBAction func autoRenewableGetInfo() {
getInfo(autoRenewableSubscription)
}
@IBAction func autoRenewablePurchase() {
purchase(autoRenewableSubscription, atomically: autoRenewableIsAtomic)
}
@IBAction func autoRenewableVerifyPurchase() {
verifyPurchase(autoRenewableSubscription)
}

func getInfo(_ purchase: RegisteredPurchase) {

NetworkActivityIndicatorManager.networkOperationStarted()
Expand All @@ -73,10 +126,10 @@ class ViewController: UIViewController {
}
}

func purchase(_ purchase: RegisteredPurchase) {
func purchase(_ purchase: RegisteredPurchase, atomically: Bool) {

NetworkActivityIndicatorManager.networkOperationStarted()
SwiftyStoreKit.purchaseProduct(appBundleId + "." + purchase.rawValue, atomically: true) { result in
SwiftyStoreKit.purchaseProduct(appBundleId + "." + purchase.rawValue, atomically: atomically) { result in
NetworkActivityIndicatorManager.networkOperationFinished()

if case .success(let purchase) = result {
Expand Down Expand Up @@ -132,7 +185,7 @@ class ViewController: UIViewController {
let productId = self.appBundleId + "." + purchase.rawValue

switch purchase {
case .autoRenewablePurchase:
case .autoRenewableWeekly, .autoRenewableMonthly, .autoRenewableYearly:
let purchaseResult = SwiftyStoreKit.verifySubscription(
type: .autoRenewable,
productId: productId,
Expand Down
24 changes: 12 additions & 12 deletions SwiftyStoreKit-tvOS-Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.AppleTV.Storyboard" version="3.0" toolsVersion="11762" systemVersion="16A313a" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder.AppleTV.Storyboard" version="3.0" toolsVersion="13771" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="appleTV" orientation="landscape">
<adaptation id="light"/>
</device>
<dependencies>
<deployment identifier="tvOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="SwiftyStoreKit_tvOS_Demo" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="SwiftyStoreKit_tvOSDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
Expand All @@ -27,7 +27,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="info 1"/>
<connections>
<action selector="getInfo1" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="nHA-8L-kz5"/>
<action selector="nonConsumableGetInfo" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="KQL-dt-eTv"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fad-e7-Q2a">
Expand All @@ -36,7 +36,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="info 2"/>
<connections>
<action selector="getInfo2" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="qYx-Ai-IvG"/>
<action selector="autoRenewableGetInfo" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="Xf3-53-eEI"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lOy-18-mr9">
Expand All @@ -45,7 +45,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="purchase 1"/>
<connections>
<action selector="purchase1" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="K3z-2d-B9r"/>
<action selector="nonConsumablePurchase" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="8j3-oq-8F4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VG3-26-V8F">
Expand All @@ -54,7 +54,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="purchase 2"/>
<connections>
<action selector="purchase2" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="C85-0E-sl9"/>
<action selector="autoRenewablePurchase" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="qSE-zE-v41"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="984-qT-rjk">
Expand All @@ -63,7 +63,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="restore"/>
<connections>
<action selector="restorePurchases" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="7nH-dy-bg5"/>
<action selector="restorePurchases" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="Ce8-Mj-esn"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="TE5-kT-3nP">
Expand All @@ -72,7 +72,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="verify1"/>
<connections>
<action selector="verifyPurchase1" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="rJq-xw-YhW"/>
<action selector="nonConsumableVerifyPurchase" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="VkV-9u-PqD"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iYp-Z0-czh">
Expand All @@ -81,7 +81,7 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="verify2"/>
<connections>
<action selector="verifyPurchase2" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="d3O-JX-afR"/>
<action selector="autoRenewableVerifyPurchase" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="kqM-Mg-BKc"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hdi-nV-Cky">
Expand All @@ -90,11 +90,11 @@
<inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
<state key="normal" title="receipt"/>
<connections>
<action selector="verifyReceipt" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="f73-g0-uzV"/>
<action selector="verifyReceipt" destination="BYZ-38-t0r" eventType="primaryActionTriggered" id="N3M-ke-Dgy"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.84593750000000001" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 1 addition & 1 deletion SwiftyStoreKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pod::Spec.new do |s|

s.source_files = 'SwiftyStoreKit/*.{swift}'

s.screenshots = ["https://github.com/bizz84/SwiftyStoreKit/raw/master/Screenshots/Preview.png","https://github.com/bizz84/SwiftyStoreKit/raw/master/Screenshots/Preview2.png"]
s.screenshots = ["https://github.com/bizz84/SwiftyStoreKit/raw/master/Screenshots/Preview.jpg"]

s.requires_arc = true
end

0 comments on commit f4a99d3

Please sign in to comment.