Purchases 0.10.2

Purchases 0.10.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Mar 2018

Maintained by Jacob Eiting.


Downloads

Total328
Week0
Month36

Installs

Apps28
Test Targets2
powered by Segment

GitHub

Stars0
Watchers0
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files18
LOCLines of Code 763


Purchases 0.10.2

  • By
  • RevenueCat, Inc.

RevenueCat

Purchases.framework

Version License

Purchases is a client for the RevenueCat subscription and purchase tracking system. It is an open source framework that provides a wrapper around StoreKit and the RevenueCat backend to make implementing iOS in app purchases easy.

Installation

Purchases is available through CocoaPods and Carthage

CocoaPods

pod "Purchases"

Carthage

github "revenuecat/purchases-ios"

Getting Started

1. Create a RevenueCat Account

Go to RevenueCat, create an account, and obtain an API key for your application.

2. In your app instantiate an RCPurchases object with your secret.

import Purchases

self.purchases = RCPurchases(apiKey: "myappapikey",
                             appUserID: "uniqueidforuser")!
#import <Purchases/Purchases.h>

RCPurchases *purchases = [[RCPurchases alloc] initWithAPIKey:@"myappAPIKey"
                                                   appUserID:@"uniqueidforuser"];

3. Create a delegate to handle new purchases and purchaser info.

self.purchases.delegate = self

func purchases(_ purchases: RCPurchases,
          completedTransaction transaction: SKPaymentTransaction,
          withUpdatedInfo purchaserInfo: RCPurchaserInfo) {
  DispatchQueue.main.async {
    self.handleNewPurchaserInfo(info: purchaserInfo)
  }
}

func purchases(_ purchases: RCPurchases,
                   failedTransaction transaction: SKPaymentTransaction,
                   withReason failureReason: Error) {
  DispatchQueue.main.async {
    displayErrorMessage((failureReason as! NSError).localizedDescription)
  }
}

func purchases(_ purchases: RCPurchases, receivedUpdatedPurchaserInfo purchaserInfo: RCPurchaserInfo) {
  DispatchQueue.main.async {
    handleNewPurchaserInfo(info: purchaserInfo)
  }
}
purchases.delegate = delegateObject;

- (void)purchases:(RCPurchases *)purchases
    completedTransaction:(SKPaymentTransaction *)transaction
         withUpdatedInfo:(RCPurchaserInfo *)purchaserInfo {
         [self saveNewPurchaserInfo:purchaserInfo];
}

- (void)purchases:(RCPurchases *)purchases 
failedTransaction:(SKPaymentTransaction *)transaction 
       withReason:(NSError *)failureReason {
       [self displayErrorMessage:failureReason.localizedDescription];
}

- (void)purchases:(RCPurchases *)purchases receivedUpdatedPurchaserInfo:(RCPurchaserInfo *)purchaserInfo {
  [self saveNewPurchaserInfo:purchaserInfo]; 
}

4. Fetch products

productIDs = /* */

self.purchases.products(withIdentifiers: productIDs) { (products) in
  if producst.count == 0 {
    displayErrorMessage:("Error fetching products")
  } else {
    let mySubscriptionProduct = products[0]
    displayProduct(mySubscriptionProduct);
  }
}
NSSet *myProductIDs = [NSSet setWithArray:@["com.myapp.subscription_product"]];

[self.purchases productsWithIdentifiers:myProductIDs completion:^(NSArray<SKProduct *> * _Nonnull products) {
  if (products.count == 0) {
    [self displayErrorMessage:@"Error fetching products"];
  } else {
    SKProduct *mySubscriptionProduct = products[0];
    [self displayProduct:mySubscriptionProduct];
  }
}]

5. Make a purchase

self.purchases.makePurchase(mySubscriptionProduct)
[purchases makePurchase:mySubscriptionProduct];

7. Handle user information updates

The latest purchaser information can come at any time, be prepared to receive it

func purchases(_ purchases: RCPurchases,
               receivedUpdatedPurchaserInfo purchaserInfo: RCPurchaserInfo) {
    DispatchQueue.main.async {
      self.handleNewPurchaserInfo(info: purchaserInfo)
    }
}
- (void)purchases:(RCPurchases *)purchases receivedUpdatedPurchaserInfo:(RCPurchaserInfo *)purchaserInfo {
    dispatch_async(dispatch_get_main_queue(), ^{
        [self handleNewPurchaserInfo:purchaserInfo];
    });
}

6. Make $$$

That's it. RevenueCat will handle all purchase verification and purchase tracking for you so you can focus on building your app.