InApps iOS
Instance Methods | Protected Types | Properties
LDInAppService Class Reference

Inherits NSObject.

Instance Methods

(instancetype) - init
 
(void) - addPurchaseObserver:
 
(void) - removePurchaseObserver:
 
(void) - start
 
(void) - fetchProducts:completion:
 
(LDInAppProduct *) - productForId:
 
(BOOL) - isPurchased:
 
(NSInteger) - stockOfProduct:
 
(void) - restorePurchases:
 
(BOOL) - canPurchase
 
(void) - purchase:completion:
 
(void) - purchase:quantity:completion:
 
(NSInteger) - consume:quantity:
 
(void) - finishPurchase:
 
(void) - setValidationHandler:
 
(void) - setLudeiServerValidationHandler
 

Protected Types

typedef void(^ LDFetchProductsCallback) (NSArray *products, NSError *error)
 
typedef void(^ LDValidationCompletion) (NSError *error)
 
typedef void(^ LDValidationHandler) (NSData *validationReceipt, NSString *productId, LDValidationCompletion completion)
 

Properties

NSMutableArray * products
 
BOOL autoFinishPurchases
 

Method Documentation

- (void) addPurchaseObserver: (id< LDInAppPurchaseObserver >)  observer

Adds an observer.

Parameters
observerThe observer.
- (BOOL) canPurchase

Returns YES if the device is allowed to make payments.

Returns
True if the device is allowed to make payments.
- (NSInteger) consume: (NSString *)  productId
quantity: (NSInteger)  quantity 

Consumes a quantity of consumable products. Uses the local purchase database, so it only works if savePurchases property is enabled.

Parameters
productIdThe product id.
quantityThe quantity of the product.
Returns
The quantity of consumed purchases.
- (void) fetchProducts: (NSArray *)  productIds
completion: (LDFetchProductsCallback)  completion 

Requests information about products from Apple Store. Products are saved in a local DB if saveProducts property is set to YES.

Parameters
productIdsThe ids of the products.
completionCompletion.
- (void) finishPurchase: (NSString *)  transactionId

Removes a finished purchase transaction from the queue.

Parameters
transactionIdThe transaction id.
See also
autoFinishPurchases. If the property is set finishPurchase is automatically called.
- (BOOL) isPurchased: (NSString *)  productId

Returns YES if the product is purchased. Uses the local purchase database, so it only works if savePurchases property is enabled.

Parameters
productIdThe product id of the product to check.
Returns
True if the product is purchased.
- (LDInAppProduct*) productForId: (NSString *)  identifier

Gets product info for product indetifier It uses a local cache, so fetchProducts have to be called before if products are not saved from previus executions.

Parameters
identifierThe id of the product to get.
Returns
The product that has that id.
- (void) purchase: (NSString *)  productId
completion: (void(^)(NSError *error))  completion 

Purchases a product.

Parameters
productIdThe id of the product to purchase.
completionAn error if the process fails.
See also
LDInAppPurchaseObserver
- (void) purchase: (NSString *)  productId
quantity: (NSInteger)  quantity
completion: (void(^)(NSError *error))  completion 

Purchases a quantity of a specific product.

Parameters
productIdThe id of the purchased product.
quantityThe quatity to purchase.
completionAn error if the process fails.
See also
LDInAppPurchaseObserver
- (void) removePurchaseObserver: (id< LDInAppPurchaseObserver >)  observer

Removes an observer.

Parameters
observerThe observer.
- (void) restorePurchases: (void(^)(NSError *error))  completion

Restores already completed transactions and purchases. LDInAppPurchaseObserver observer is called again for each transaction.

Parameters
completionCompletion.
See also
LDInAppPurchaseObserver
- (void) setLudeiServerValidationHandler

Use Ludei's server to validate purchases. To enable validatioon using Ludei's server you first need to create an account in Ludei's Cloud server and create a project with you bundleId.

- (void) setValidationHandler: (LDValidationHandler)  handler

Sets a custom purchase validation handler. Purchases are always validated to TRUE by default. Set a custom validation handler to use you own custom server to validate purchases.

Parameters
handlerThe custom validation handler.
- (void) start

Starts processing transactions and receiving LDInAppPurchaseObserver notifications. You have to call this method when your LDInAppPurchaseObservers are ready.

- (NSInteger) stockOfProduct: (NSString *)  productId

Returns the quantity of available items for a specific productId. Uses the local purchase database, so it only works if savePurchases property is enabled. For consumable products it returns the avaiable items. For non consumable products it returns 1 i purchased, 0 otherwise.

Parameters
productIdThe product id of the product to check.
Returns
The stock of the given product.

Property Documentation

- (BOOL) autoFinishPurchases
readwritenonatomicassign

Defines if purchases should finish automatically or not.

- (NSMutableArray*) products
readnonatomicassign

The cached products.


The documentation for this class was generated from the following file: