Skip to main content

bfgPurchase Class

Manages Apple's In-App Purchases for Free-to-Play games. More...#import <bfgPurchase.h>

Class Methods

("Deprecated since iOS SDK 7.0. Refer to acquireProductInformation:productId instead.") + __deprecated_msg
 
(BOOL) + acquireProductInformation:
 
(BOOL) + acquireProductInformationForProducts:
 
(BOOL) + canStartPurchase:
 
(void) + processDeferredPayments
 
(BOOL) + hasDeferredPayments
 
("Deprecated since iOS SDK 7.0. Refer to startPurchase:productId instead.") + __deprecated_msg
 
(void) + startPurchase:
 
(void) + startPurchase:details1:details2:details3:additionalDetails:
 
("Deprecated since iOS SDK 7.0. Refer to finishPurchase:productId instead.") + __deprecated_msg
 
(void) + finishPurchase:
 
("Deprecated since iOS SDK 7.0. Refer to isPurchaseActive:productId instead.") + __deprecated_msg
 
(BOOL) + isPurchaseActive:
 
(BOOL) + isRestoreActive
 
("Deprecated since iOS SDK 7.0. Refer to productInformation:productId instead.") + __deprecated_msg
 
(NSDictionary *) + productInformation:
 
(void) + restorePurchases
 
(BOOL) + startService
 
(BOOL) + startService:
 
(NSArray< bfgPurchaseObject * > *) + deliverablePurchases
 Completed purchases that have not been granted to the user. More...
 
(BOOL) + purchaseActivityInProgress
 

Detailed Description

Manages Apple's In-App Purchases for Free-to-Play games. If you are using these APIs, you should become an observer for the following events:
  • NOTIFICATION_PURCHASE_PRODUCTINFORMATION
  • NOTIFICATION_PURCHASE_SUCCEEDED
  • NOTIFICATION_PURCHASE_FAILED
  • NOTIFICATION_PURCHASE_DEFERRED
  • NOTIFICATION_RESTORE_SUCCEEDED
  • NOTIFICATION_RESTORE_FAILED
It is important to begin observing these events before starting the bfgPurchase service.Occasionally a game will need to support functionality beyond what is provided by bfgPurchase. For example, bfgPurchase does not support downloadable content. In this case, you can talk to your producer about setting purchaseExpertMode to "1". With purchaseExpertMode enabled, you will receive SKPaymentTransactions with your bfgPurchaseObject when purchasing and restoring. It is your responsibility to call finishPurchase on both new purchases and restores if you enable expert mode. In non-expert mode, restores will close themselves.
Since
4.0.0

Method Documentation

◆ __deprecated_msg [1/5]

+ ("Deprecated since iOS SDK 7.0. Refer to) productInformation:
Returns
Product information related to the default product.
See also
+ productInformation:
Deprecated:\n Deprecated since iOS SDK 7.0. Refer to productInformation:productId instead.
Since
4.0.0

◆ __deprecated_msg [2/5]

+ ("Deprecated since iOS SDK 7.0. Refer to) startPurchase:
Convenience method for calling startPurchase:details1:details2:details3:additionalDetails with nil details and nil additional details.
See also
+ startPurchase: details1:details2:details3:additionalDetails:
Deprecated:\n Deprecated since iOS SDK 7.0. Refer to startPurchase:productId instead.
Since
4.2.0

◆ __deprecated_msg [3/5]

+ ("Deprecated since iOS SDK 7.0. Refer to) isPurchaseActive:
Returns
Return values
YESThe default product is currently being processed for purchase.
NOPurchase already in-flight, restore in-flight, or other restriction preventing purchase.
Deprecated:\n Deprecated since iOS SDK 7.0. Refer to isPurchaseActive:productId instead.
Since
4.0.0

◆ __deprecated_msg [4/5]

+ ("Deprecated since iOS SDK 7.0. Refer to) acquireProductInformation:
Requests product information of the default product from the App Store. This method must be called before the default product can be purchased.
See also
+ acquireProductInformationForProducts:
Returns
Return values
YESThe request for product information is sent to the App Store.
NOThe user is offline or the default productId is already being requested.
Deprecated:\n Deprecated since iOS SDK 7.0. Refer to acquireProductInformation:productId instead.
Since
4.0.0

◆ __deprecated_msg [5/5]

+ ("Deprecated since iOS SDK 7.0. Refer to) finishPurchase:
Convenience method for calling finishPurchase: with the default productId.
See also
+ finishPurchase:
Deprecated:\n Deprecated since iOS SDK 7.0. Refer to finishPurchase:productId instead.
Since
4.2.0

◆ acquireProductInformation:

+ (BOOL) acquireProductInformation: (NSString *) productId
Requests product information from the App Store. This method must be called before the requested product can be purchased.If multiple products are being requested, it is much more efficient to use acquireProductInformationForProducts: rather than repeated calls to this method.
See also
+ acquireProductInformationForProducts:
Parameters
productIdIdentifier of a product that can be purchased in game.
Returns
Return values
YESThe request for product information is sent to the App Store.
NOThe product information is already being requested.
Since
4.0.0

◆ acquireProductInformationForProducts:

+ (BOOL) acquireProductInformationForProducts: (NSSet *) productIds
Requests product information from the App Store. This method must be called before the requested products can be purchased.
Parameters
productIdsSet of identifiers of products that can be purchased in the game.
This method will keep trying to acquire product information if connectivity issues prevent the request from succeeding.
Returns
Return values
YESThe request for product information has been sent to the App Store.
NOAll productIds are already being requested.
Since
4.2.0

◆ canStartPurchase:

+ (BOOL) canStartPurchase: (NSString *) productId
Checks whether it is possible to purchase a product at this time.For most applications, this is the API to call. You should specify a productId that was defined in iTunes Connect by your producer.This method presents the UI to users as they begin the purchase process.In order to provide a quick result, this method does not try to connect to Big Fish Games' purchase services server. This check will occur in startPurchase before a purchase is sent to Apple.
Returns
Return values
YESPurchase will succeed if started.
NOPurchase already in-flight, restore in-flight, or other restriction preventing purchase.
Since
4.2.0

◆ deliverablePurchases

+ (NSArray< bfgPurchaseObject * > *) deliverablePurchases
Completed purchases that have not been granted to the user. When a purchase completes, you will receive a notification of its success or failure. At this time, award the purchase to the user. This method gives you a secondary way of accessing purchases that should be awarded after the notification has fired.
Note
You must start the bfgPurchase service before calling this method.
Returns
Purchase objects that were successfully purchased but have not had "finishPurchase" called on them.
Since
5.9

◆ finishPurchase:

+ (void) finishPurchase: (NSString *) productId
A call to this method is necessary for all successful purchases. Failed purchases and restores do not need to be finished.After performing the unlock and PERSISTING IT, this method must be called to take the purchase off the queue. If this method is not called, the app will be notified of the purchase every time bfgPurchase is restarted. The product cannot be purchased again until the previous purchase has been finished.Calling this method on a productId that is not currently being purchased does nothing.
Parameters
productIdThe ID of the product to take off the queue.
Since
4.2.0

◆ hasDeferredPayments

+ (BOOL) hasDeferredPayments
Used to determine if the app has deferred payments from promoted in-app purchases.
Since
7.6.0

◆ isPurchaseActive:

+ (BOOL) isPurchaseActive: (NSString *) productId
Parameters
productIdID of product to query if purchase is active.
Returns
Return values
YESPurchase is being processed.
NOPurchase already in-flight, restore in-flight, or other restriction preventing purchase.
Since
4.0.0

◆ isRestoreActive

+ (BOOL) isRestoreActive
Returns
Return values
YESRestore is being processed or verified.
NORestore in-flight or other restriction preventing restore.
Since
4.2.0

◆ processDeferredPayments

+ (void) processDeferredPayments
Used to process deferred payments from promoted in-app purchases.
Since
7.6.0

◆ productInformation:

+ (NSDictionary *) productInformation: (NSString *) productId
Product information is obtained from Apple during acquireProductInformationForProducts: and held in a transient dictionary.Games should not persist this data but should acquire it on each launch from the iTunes Store.
Returns
A dictionary of information regarding the product with the following keys (pre-processor defines):
Return values
PRODUCT_INFO_PRODUCT_IDApple ID of the product.
PRODUCT_INFO_PRICEPrice as a number.
PRODUCT_INFO_PRICE_STRPrice as localized string.
PRODUCT_INFO_TITLETitle of product.
PRODUCT_INFO_DESCRIPTIONDescription of product.
PRODUCT_INFO_CURRENCYCurrency price is denoted in.
Since
4.0.0

◆ purchaseActivityInProgress

+ (BOOL) purchaseActivityInProgress
Checks if a purchase / restore is in progress. Should not be displayed.
Returns
Return values
YESPurchase or restore in progress.
NOPurchase already in-flight, restore in-flight, or other restriction preventing purchase.
Since
4.2.0

◆ restorePurchases

+ (void) restorePurchases
Restores previous purchases. Receives the same NOTIFICATION_PURCHASE_SUCCEEDED notification as the original purchase.
Since
4.2.0

◆ startPurchase:

+ (void) startPurchase: (NSString *) productId
Convenience method for calling startPurchase:details1:details2:details3:additionalDetails with the default productId, nil details, and nil additional details.
See also
+ startPurchase: details1:details2:details3:additionalDetails:
Since
4.2.0

◆ startPurchase:details1:details2:details3:additionalDetails:

+ (void) startPurchase:(NSString *) productId
details1:(NSString *) details1
details2:(NSString *) details2
details3:(NSString *) details3
additionalDetails:(NSDictionary *) additionalDetails 
Attempt an In-App Purchase with the iTunes store.
Parameters
productIdIdentifier of product to be purchased. Originates from the iTunes Store.
details1An alpha-numeric label to categorize the event. May be nil.
details2An alpha-numeric label to categorize the event. May be nil.
details3An alpha-numeric label to categorize the event. May be nil.
additionalDetailsAdditional data to be associated with this productId. This value may be nil. If not nil, the value must be a flat dictionary containing only NSString * as keys and values.
This method posts one of the following notifications on the main thread:
  • NOTIFICATION_PURCHASE_SUCCEEDED – Perform the unlock, persist the purchase, and call finishPurchase:
  • NOTIFICATION_PURCHASE_FAILED – Inform the user the purchase failed.
These notifications contain userInfo, with BFG_PURCHASE_OBJECT_USER_INFO_KEY as a key to the (bfgPurchaseObject *)purchaseObject
See also
bfgPurchaseObject
Since
4.2.0

◆ startService

+ (BOOL) startService
Calling startService on bfgPurchases enables its functionality and causes it to resume processing any operations that were already in progress. All notification listeners should be set up prior to calling start.
Returns
Return values
YESPurchase has started.
NOPurchase has previously started.
Since
4.2.0

◆ startService:

+ (BOOL) startService: (NSError *__autoreleasing *) error
Calling startService on bfgPurchases enables its functionality and causes it to resume processing any operations that were already in progress. All notification listeners should be set up prior to calling start.
Parameters
errorIf service fails to start, error will contain the reason. Otherwise error is nil.
Returns
Return values
YESPurchase has started.
NOPurchase has previously started.
Since
4.7.0