RCPurchases

@interface RCPurchases : NSObject

RCPurchases is the entry point for Purchases.framework. It should be instantiated as soon as your app has a unique user id for your user. This can be when a user logs in if you have accounts or on launch if you can generate a random user identifier.

Warning

Only one instance of RCPurchases should be instantiated at a time! Use a configure method to let the framework handle the singleton instance for you.
  • Configures an instance of the Purchases SDK with a specified API key. The instance will be set as a singleton. You should access the singleton instance using [RCPurchases sharedPurchases]

    Note

    Use this initializer if your app does not have an account system. RCPurchases will generate a unique identifier for the current device and persist it to NSUserDefaults. This also affects the behavior of restoreTransactionsForAppStoreAccount.

    Declaration

    Objective-C

    + (nonnull instancetype)configureWithAPIKey:(nonnull NSString *)APIKey;

    Swift

    class func configure(withAPIKey APIKey: String) -> Self

    Parameters

    APIKey

    The API Key generated for your app from https://app.revenuecat.com/

    Return Value

    An instantiated RCPurchases object that has been set as a singleton.

  • Configures an instance of the Purchases SDK with a specified API key and app user ID. The instance will be set as a singleton. You should access the singleton instance using [RCPurchases sharedPurchases]

    Note

    Best practice is to use a salted hash of your unique app user ids.

    Warning

    Use this initializer if you have your own user identifiers that you manage.

    Declaration

    Objective-C

    + (nonnull instancetype)configureWithAPIKey:(nonnull NSString *)APIKey
                                      appUserID:(NSString *_Nullable)appUserID;

    Swift

    class func configure(withAPIKey APIKey: String, appUserID: String?) -> Self

    Parameters

    APIKey

    The API Key generated for your app from https://app.revenuecat.com/

    appUserID

    The unique app user id for this user. This user id will allow users to share their purchases and subscriptions across devices. Pass nil if you want RCPurchases to generate this for you.

    Return Value

    An instantiated RCPurchases object that has been set as a singleton.

  • Configures an instance of the Purchases SDK with object with a custom userDefaults. Use this constructor if you want to sync status across a shared container, such as between a host app and an extension. The instance of the Purchases SDK will be set as a singleton. You should access the singleton instance using [RCPurchases sharedPurchases]

    Declaration

    Objective-C

    + (nonnull instancetype)configureWithAPIKey:(nonnull NSString *)APIKey
                                      appUserID:(NSString *_Nullable)appUserID
                                   userDefaults:
                                       (NSUserDefaults *_Nullable)userDefaults;

    Swift

    class func configure(withAPIKey APIKey: String, appUserID: String?, userDefaults: UserDefaults?) -> Self

    Parameters

    APIKey

    The API Key generated for your app from https://app.revenuecat.com/

    appUserID

    The unique app user id for this user. This user id will allow users to share their purchases and subscriptions across devices. Pass nil if you want RCPurchases to generate this for you.

    userDefaults

    Custom userDefaults to use

    Return Value

    An instantiated RCPurchases object that has been set as a singleton.

  • Declaration

    Objective-C

    + (nonnull instancetype)sharedPurchases;

    Swift

    class func shared() -> Self

    Return Value

    A singleton RCPurchases object. Call this after a configure method to access the singleton.

  • Sets an instance of the Purchases SDK as a singleton. The configure methods call this internally so it’s preferably to set the default instance through a configure method. Use this method only if you want to override what the configure methods are doing.

    Declaration

    Objective-C

    + (void)setDefaultInstance:(nonnull RCPurchases *)instance;

    Swift

    class func setDefaultInstance(_ instance: RCPurchases)
  • Initializes an RCPurchases object with specified API key.

    Note

    Use this initializer if your app does not have an account system. RCPurchases will generate a unique identifier for the current device and persist it to NSUserDefaults. This also affects the behavior of restoreTransactionsForAppStoreAccount.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithAPIKey:(nonnull NSString *)APIKey;

    Swift

    init(apiKey APIKey: String)

    Parameters

    APIKey

    The API Key generated for your app from https://app.revenuecat.com/

    Return Value

    An instantiated RCPurchases object

  • Initializes an RCPurchases object with specified API key and app user ID.

    Note

    Best practice is to use a salted hash of your unique app user ids.

    Warning

    Use this initializer if you have your own user identifiers that you manage.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithAPIKey:(nonnull NSString *)APIKey
                                 appUserID:(NSString *_Nullable)appUserID;

    Swift

    init(apiKey APIKey: String, appUserID: String?)

    Parameters

    APIKey

    The API Key generated for your app from https://app.revenuecat.com/

    appUserID

    The unique app user id for this user. This user id will allow users to share their purchases and subscriptions across devices. Pass nil if you want RCPurchases to generate this for you.

    Return Value

    An instantiated RCPurchases object

  • Initializes an RCPurchases object with a custom userDefaults. Use this constructor if you want to sync status across a shared container, such as between a host app and an extension.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithAPIKey:(nonnull NSString *)APIKey
                                 appUserID:(NSString *_Nullable)appUserID
                              userDefaults:(NSUserDefaults *_Nullable)userDefaults;

    Swift

    init(apiKey APIKey: String, appUserID: String?, userDefaults: UserDefaults?)

    Parameters

    APIKey

    The API Key generated for your app from https://app.revenuecat.com/

    appUserID

    The unique app user id for this user. This user id will allow users to share their purchases and subscriptions across devices. Pass nil if you want RCPurchases to generate this for you.

    userDefaults

    Custom userDefaults to use

    Return Value

    An instantiated RCPurchases object

  • The appUserID used by RCPurchases. If not passed on initialization this will be generated and cached by RCPurchases.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull appUserID;

    Swift

    var appUserID: String { get }
  • Set this to true if you are passing in an appUserID but it is anonymous, this is true by default if you didn’t pass an appUserID If a user tries to purchase a product that is active on the current app store account, we will treat it as a restore and alias the new ID with the previous id.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL allowSharingAppStoreAccount;

    Swift

    var allowSharingAppStoreAccount: Bool { get set }
  • Default to YES, set this to NO if you are finishing transactions with your own StoreKit queue listener

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL finishTransactions;

    Swift

    var finishTransactions: Bool { get set }
  • Send your attribution data to RevenueCat so you can track the revenue generated by your different campaigns.

    Declaration

    Objective-C

    - (void)addAttributionData:(nonnull NSDictionary *)data
                   fromNetwork:(RCAttributionNetwork)network;

    Swift

    func addAttributionData(_ data: [AnyHashable : Any], from network: RCAttributionNetwork)

    Parameters

    data

    Dictionary provided by the network. See https://docs.revenuecat.com/docs/attribution

    network

    Enum for the network the data is coming from, see RCAttributionNetwork for supported networks

  • Delegate for RCPurchases instance. The delegate is responsible for handling completed purchases and updated purchaser information.

    Note

    RCPurchases will not listen for any purchases until the delegate is set. This prevents transactions from being processed before your app is ready to handle them.

    Declaration

    Objective-C

    @property (readwrite, nonatomic) id<RCPurchasesDelegate> _Nullable delegate;

    Swift

    weak var delegate: RCPurchasesDelegate? { get set }
  • Fetch the configured entitlements for this user. Entitlements allows you to configure your in-app products via RevenueCat and greatly simplifies management. See the guide (https://docs.revenuecat.com/v1.0/docs/entitlements) for more info.

    Entitlements will be fetched and cached on instantiation so that, by the time they are needed, your prices are loaded for your purchase flow. Time is money.

    Declaration

    Objective-C

    - (void)entitlements:
        (nonnull void (^)(NSDictionary<NSString *, RCEntitlement *> *_Nullable))
            completion;

    Swift

    func entitlements(_ completion: @escaping ([String : RCEntitlement]?) -> Void)

    Parameters

    completion

    A completion block called when entitlements is available. Called immediately if entitlements are cached. Entitlements can be nil if an error occurred.

  • Fetches the SKProducts for your IAPs for given productIdentifiers. Use this method if you aren’t using -entitlements:. You should use entitlements though.

    Note

    completion may be called without SKProducts that you are expecting. This is usually caused by iTunesConnect configuration errors. Ensure your IAPs have the Ready to Submit status in iTunesConnect. Also ensure that you have an active developer program subscription and you have signed the latest paid application agreements.

    Declaration

    Objective-C

    - (void)
    productsWithIdentifiers:(nonnull NSArray<NSString *> *)productIdentifiers
                 completion:
                     (nonnull void (^)(NSArray<SKProduct *> *_Nonnull))completion;

    Swift

    func products(withIdentifiers productIdentifiers: [String], completion: @escaping ([SKProduct]) -> Void)

    Parameters

    productIdentifiers

    A set of product identifiers for in app purchases setup via iTunesConnect. This should be either hard coded in your application, from a file, or from a custom endpoint if you want to be able to deploy new IAPs without an app update.

    completion

    An @escaping callback that is called with the loaded products. If the fetch fails for any reason it will return an empty array.

  • Purchase the passed SKProduct.

    Call this method when a user has decided to purchase a product. Only call this in direct response to user input.

    From here Purhases will handle the purchase with StoreKit and call purchases:completedTransaction:withUpdatedInfo: or purchases:failedTransaction:withReason: on the RCPurchases delegate object.

    Note

    You do not need to finish the transaction yourself in the delegate, Purchases will handle this for you.

    Declaration

    Objective-C

    - (void)makePurchase:(nonnull SKProduct *)product;

    Swift

    func makePurchase(_ product: SKProduct)

    Parameters

    product

    The SKProduct the user intends to purchase

  • This method will post all purchases associated with the current App Store account to RevenueCat and become associated with the current appUserID. If the receipt is being used by an existing user, the current appUserID will be aliased together with the appUserID of the existing user. Going forward, either appUserID will be able to reference the same user.

    You shouldn’t use this method if you have your own account system. In that case restoration is provided by your app passing the same appUserId used to purchase originally.

    Triggers -purchases:receivedUpdatedPurchaserInfo: delegate method to be called.

    Note

    This may force your users to enter the App Store password so should only be performed on request of the user. Typically with a button in settings or near your purchase UI.

    Declaration

    Objective-C

    - (void)restoreTransactionsForAppStoreAccount;

    Swift

    func restoreTransactionsForAppStoreAccount()
  • Computes whether or not a user is eligible for the introductory pricing period of a given product. You should use this method to determine whether or not you show the user the normal product price or the introductory price. This also applies to trials (trials are considered a type of introductory pricing).

    Note

    If you have multiple subscription groups you will need to specify which products belong to which subscription groups on https://app.revenuecat.com/. If RevenueCat can’t definitively compute the eligibilty, most likely because of missing group information, it will return RCIntroEligibilityStatusUnknown. The best course of action on unknown status is to display the non-intro pricing, to not create a misleading situation.

    Declaration

    Objective-C

    - (void)
    checkTrialOrIntroductoryPriceEligibility:
        (nonnull NSArray<NSString *> *)productIdentifiers
                                  completion:
                                      (nonnull RCReceiveIntroEligibilityBlock)
                                          receiveEligibility;

    Swift

    func checkTrialOrIntroductoryPriceEligibility(_ productIdentifiers: [String], completion receiveEligibility: @escaping RCReceiveIntroEligibilityBlock)

    Parameters

    productIdentifiers

    Array of product identifiers for which you want to compute eligibility

    receiveEligibility

    A block that receives a dictionary of product_id -> RCIntroEligibility.

  • Reads the App Store receipt and reads the original application version. Use this if RCPurchaserInfo.originalApplicationVersion is nil. Triggers purchases:receivedUpdatedPurchaserInfo: delegate method to be called;

    Declaration

    Objective-C

    - (void)updateOriginalApplicationVersion;

    Swift

    func updateOriginalApplicationVersion()
  • Forces a refresh of the purchaser info. This will happen automatically in most cases and shouldn’t be called. Triggers purchases:receivedUpdatedPurchaserInfo: delegate method to be called;

    Declaration

    Objective-C

    - (void)updatePurchaserInfo;

    Swift

    func updatePurchaserInfo()
  • This version of the Purchases framework

    Declaration

    Objective-C

    + (nonnull NSString *)frameworkVersion;

    Swift

    class func frameworkVersion() -> String
  • This function will alias two appUserIDs together.

    Declaration

    Objective-C

    - (void)createAlias:(nonnull NSString *)alias;

    Swift

    func createAlias(_ alias: String)

    Parameters

    alias

    The new appUserID that should be linked to the currently identified appUserID

  • This function will alias two appUserIDs together.

    Declaration

    Objective-C

    - (void)createAlias:(nonnull NSString *)alias
             completion:(nonnull void (^)(NSError *_Nullable))completion;

    Swift

    func createAlias(_ alias: String, completion: @escaping (Error?) -> Void)

    Parameters

    alias

    The new appUserID that should be linked to the currently identified appUserID

    completion

    An optional completion block called when the aliasing has been successful. This completion block will receive an error if there’s been one.

  • This function will identify the current user with an appUserID. Typically this would be used after a logout to identify a new user without calling configure

    Declaration

    Objective-C

    - (void)identify:(NSString *_Nullable)appUserID;

    Swift

    func identify(_ appUserID: String?)

    Parameters

    appUserID

    The appUserID that should be linked to the currently user

  • Resets the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the cache.

    Declaration

    Objective-C

    - (void)reset;

    Swift

    func reset()