Latest 1.2.1
Homepage https://github.com/glassonion1/RxStoreKit
License MIT
Platforms ios 9.0, requires ARC
Dependencies RxSwift, RxCocoa
Authors

Version
License
Platform

RxStoreKit is lightweight and easy to use Rx support for StoreKit(In-App Purchases).

Usage

Request Products

import StoreKit
import RxSwift
import RxStoreKit

let disposeBag = DisposeBag()

let productRequest = SKProductsRequest(productIdentifiers: Set(["your app product id"]))
productRequest.rx.productsRequest
    .subscribe(onNext: { product in
        print(product)
    }).disposed(by: disposeBag)
productRequest.start()

Restore Transactions

SKPaymentQueue.default().rx.restoreCompletedTransactions()
    .subscribe(onNext: { queue in
        // paymentQueueRestoreCompletedTransactionsFinished
        print(queue)
    }, onError: { error in
        // restoreCompletedTransactionsFailedWithError
        print(queue)
    }).disposed(by: disposeBag)

Request payment

let productRequest = SKProductsRequest(productIdentifiers: Set(["xxx.xxx.xxx"]))
productRequest.rx.productsRequest
    .flatMap { response -> Observable<SKProduct> in
        return Observable.from(response.products)
    }
    .flatMap { product -> Observable<SKPaymentTransaction> in
        return SKPaymentQueue.default().rx.add(product: product)
    }
    .subscribe(onNext: { transaction in
        print(transaction)
    }).disposed(by: disposeBag)
productRequest.start()

Request receipt refresh

let receiptRefreshRequest = SKReceiptRefreshRequest()
receiptRefreshRequest.rx.request
    .subscribe(onCompleted: {
        // Refreshed receipt is available
    }, onError: { error in
        print(error)
    }).disposed(by: disposeBag)
receiptRefreshRequest.start()

Download hosting contents

Download In-App Purchase Contents

let productRequest = SKProductsRequest(productIdentifiers: Set(["xxx.xxx.xxx"]))
productRequest.rx.productsRequest
    .flatMap { response -> Observable<SKProduct> in
        return Observable.from(response.products)
    }
    .flatMap { product -> Observable<SKPaymentTransaction> in
        return SKPaymentQueue.default().rx.add(product: product)
    }
    .flatMap { transaction -> Observable<SKDownload> in
        return SKPaymentQueue.default().rx.start(downloads: transaction.downloads)
    }
    .subscribe(onNext: { download in
        print(download)
    }).disposed(by: disposeBag)
productRequest.start()

Installation

This library depends on both RxSwift and RxCocoa

CocoaPods

RxStoreKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "RxStoreKit"

Then, run following command:
$ pod install

License

RxStoreKit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "RxStoreKit",
    "version": "1.2.1",
    "summary": "StoreKit library for RxSwift",
    "description": "RxStoreKit is lightweight and easy to use Rx support for StoreKit.",
    "homepage": "https://github.com/glassonion1/RxStoreKit",
    "license": "MIT",
    "authors": {
        "Taisuke Fujita": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/glassonion1/RxStoreKit.git",
        "tag": "1.2.1"
    },
    "source_files": "Sources/**/*.{h,m,swift}",
    "dependencies": {
        "RxSwift": [
            "~> 4.1.1"
        ],
        "RxCocoa": [
            "~> 4.1.1"
        ]
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This