iap_ios.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef BB_IAP_IOS_H
  2. #define BB_IAP_IOS_H
  3. #import <bbmonkey.h>
  4. #ifdef __OBJC__
  5. #import <StoreKit/StoreKit.h>
  6. class BBIAPStore;
  7. @interface BBIAPStoreDelegate : NSObject<SKProductsRequestDelegate,SKPaymentTransactionObserver>{
  8. @private
  9. BBIAPStore *_peer;
  10. }
  11. -(id)initWithPeer:(BBIAPStore*)peer;
  12. -(void)productsRequest:(SKProductsRequest*)request didReceiveResponse:(SKProductsResponse*)response;
  13. -(void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions;
  14. -(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue*)queue;
  15. -(void)paymentQueue:(SKPaymentQueue*)queue restoreCompletedTransactionsFailedWithError:(NSError*)error;
  16. -(void)request:(SKRequest*)request didFailWithError:(NSError*)error;
  17. @end
  18. #else
  19. #include <objc/objc.h>
  20. typedef struct objc_object SKProduct;
  21. typedef struct objc_object SKProductsRequest;
  22. typedef struct objc_object SKProductsResponse;
  23. typedef struct objc_object SKPaymentQueue;
  24. typedef struct objc_object NSArray;
  25. typedef struct objc_object NSError;
  26. typedef struct objc_object SKRequest;
  27. typedef struct objc_object BBIAPStoreDelegate;
  28. typedef struct objc_object NSNumberFormatter;
  29. #endif
  30. struct BBProduct : public bbObject{
  31. BBProduct();
  32. ~BBProduct();
  33. SKProduct *product;
  34. bool valid;
  35. bbString title;
  36. bbString identifier;
  37. bbString description;
  38. bbString price;
  39. int type;
  40. bool owned;
  41. bool interrupted;
  42. };
  43. struct BBIAPStore : public bbObject{
  44. BBIAPStore();
  45. bool OpenStoreAsync( bbArray<bbGCVar<BBProduct>> products );
  46. bool BuyProductAsync( BBProduct* product );
  47. bool GetOwnedProductsAsync();
  48. bool IsRunning();
  49. int GetResult();
  50. BBProduct *FindProduct( bbString id );
  51. void OnRequestProductDataResponse( SKProductsRequest *request,SKProductsResponse *response );
  52. void OnUpdatedTransactions( SKPaymentQueue *queue,NSArray *transactions );
  53. void OnRestoreTransactionsFinished( SKPaymentQueue *queue,NSError *error );
  54. void OnRequestFailed( SKRequest *request,NSError *error );
  55. virtual void gcMark();
  56. BBIAPStoreDelegate *_delegate;
  57. NSNumberFormatter *_priceFormatter;
  58. bbArray<bbGCVar<BBProduct>> _products;
  59. bool _running;
  60. int _result;
  61. };
  62. #endif