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.
  • Enable automatic collection of Apple Search Ad attribution. Disabled by default

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, class)
        BOOL automaticAttributionCollection;
  • Enable debug logging. Useful for debugging issues with the lovely team @RevenueCat

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, class) BOOL debugLogsEnabled;
  • 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;

    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;

    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 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
                                   observerMode:(BOOL)observerMode;

    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.

    observerMode

    Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat’s backend. Default is FALSE.

    Return Value

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

  • Configures an instance of the Purchases SDK 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
                                   observerMode:(BOOL)observerMode
                                   userDefaults:
                                       (NSUserDefaults *_Nullable)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.

    observerMode

    Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat’s backend. Default is FALSE.

    userDefaults

    Custom userDefaults to use

    Return Value

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

  • Indicates whether the user is allowed to make payments.

    Declaration

    Objective-C

    + (BOOL)canMakePayments;
  • Declaration

    Objective-C

    @property (readonly, nonatomic, class) RCPurchases *_Nonnull sharedPurchases;

    Return Value

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

  • 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;
  • 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;
  • This version of the Purchases framework

    Declaration

    Objective-C

    + (nonnull NSString *)frameworkVersion;
  • Delegate for RCPurchases instance. The delegate is responsible for handling promotional product purchases and changes to purchaser information.

    Declaration

    Objective-C

    @property (readwrite, nonatomic) id<RCPurchasesDelegate> _Nullable delegate;
  • 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;
  • This function will alias two appUserIDs together.

    Declaration

    Objective-C

    - (void)createAlias:(nonnull NSString *)alias
        completionBlock:(RCReceivePurchaserInfoBlock _Nullable)completion;

    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
        completionBlock:(RCReceivePurchaserInfoBlock _Nullable)completion;

    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)resetWithCompletionBlock:
        (RCReceivePurchaserInfoBlock _Nullable)completion;
  • Get latest available purchaser info.

    Declaration

    Objective-C

    - (void)purchaserInfoWithCompletionBlock:
        (nonnull RCReceivePurchaserInfoBlock)completion;

    Parameters

    completion

    A completion block called when purchaser info is available and not stale. Called immediately if purchaser info is cached. Purchaser info can be nil if an error occurred.

  • 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/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)entitlementsWithCompletionBlock:
        (nonnull RCReceiveEntitlementsBlock)completion;

    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. If you’re having trouble see: https://www.revenuecat.com/2018/10/11/configuring-in-app-products-is-hard

    Declaration

    Objective-C

    - (void)productsWithIdentifiers:
                (nonnull NSArray<NSString *> *)productIdentifiers
                    completionBlock:(nonnull RCReceiveProductsBlock)completion;

    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 Purchases will handle the purchase with StoreKit and call the RCPurchaseCompletedBlock.

    Note

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

    Declaration

    Objective-C

    - (void)makePurchase:(nonnull SKProduct *)product
        withCompletionBlock:(nonnull RCPurchaseCompletedBlock)completion;

    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.

    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)restoreTransactionsWithCompletionBlock:
        (RCReceivePurchaserInfoBlock _Nullable)completion;
  • 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
                                     completionBlock:
                                         (nonnull RCReceiveIntroEligibilityBlock)
                                             receiveEligibility;

    Parameters

    productIdentifiers

    Array of product identifiers for which you want to compute eligibility

    receiveEligibility

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

  • Undocumented

    Declaration

    Objective-C

    - (void)paymentDiscountForProductDiscount:(SKProductDiscount *)discount
                                      product:(SKProduct *)product
                                   completion:(RCPaymentDiscountBlock)completion API_AVAILABLE(ios(12.2), macosx(10.14.4));
  • Purchase the passed SKProduct.

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

    From here Purchases will handle the purchase with StoreKit and call the RCPurchaseCompletedBlock.

    Note

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

    Declaration

    Objective-C

    - (void)makePurchase:(nonnull SKProduct *)product
            withDiscount:(SKPaymentDiscount *_Nullable)discount
         completionBlock:(nonnull RCPurchaseCompletedBlock)completion;

    Parameters

    product

    The SKProduct the user intends to purchase

    discount

    The SKPatmentDiscount to apply to the purchase