This repository has been archived by the owner on Aug 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathIAPManager.h
77 lines (53 loc) · 2.81 KB
/
IAPManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// IAPManager.h
// Classes
//
// Created by Marcel Ruegenberg on 22.11.12.
// Copyright (c) 2012 Dustlab. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#if !TARGET_OS_IPHONE
#ifndef UIApplicationWillResignActiveNotification
#define UIApplicationWillResignActiveNotification NSApplicationWillResignActiveNotification
#endif
#endif
typedef void(^PurchaseCompletionBlock)(SKPaymentTransaction *transaction);
typedef void(^ProductsCompletionBlock)(NSArray *products);
typedef void(^ErrorBlock)(NSError *error);
typedef void(^PurchasedProductsChanged)(void);
typedef void(^RestorePurchasesCompletionBlock)(void);
// use SIMULATE_PURCHASES to prevent any actual purchasing from happening, i.e
// if a user "buys" an item, the transaction immediately succeeds, without any communication with the App Store happening.
// #define SIMULATE_PURCHASES
#ifdef SIMULATE_PURCHASES
#warning In-App Purchase is only simulated!
#endif
/// A simple toolkit for non-renewables (a.k.a "Premium Features") with In-App Purchase.
/// The main goal is ease of use. Therefore, more complicated parts, like checking of receipts, are not provided.
@interface IAPManager : NSObject
+ (IAPManager *)sharedIAPManager;
- (BOOL)hasPurchased:(NSString *)productId;
#pragma mark Product Information
/// passes a set of products to the completion block
- (void)getProductsForIds:(NSArray *)productIds completion:(ProductsCompletionBlock)completionBlock __attribute__((deprecated));
/**
* passes a set of products to the completion block
* if an error occurs, `err` is called with the error object (which is potentially nil)
*/
- (void)getProductsForIds:(NSArray *)productIds completion:(ProductsCompletionBlock)completionBlock error:(ErrorBlock)errorBlock;
#pragma mark Purchase
- (void)restorePurchases;
- (void)restorePurchasesWithCompletion:(RestorePurchasesCompletionBlock)completionBlock;
- (void)restorePurchasesWithCompletion:(RestorePurchasesCompletionBlock)completionBlock error:(ErrorBlock)err;
- (void)purchaseProduct:(SKProduct *)product completion:(PurchaseCompletionBlock)completionBlock error:(ErrorBlock)err;
/// if an error occurs, `err` is called with the error object (which is potentially nil)
- (void)purchaseProductForId:(NSString *)productId completion:(PurchaseCompletionBlock)completionBlock error:(ErrorBlock)err;
/// Checks whether purchases are allowed by the App Store. This does not check whether there is a connection to the internet.
- (BOOL)canPurchase;
#pragma mark Observation
/// add a callback that should be called if a new product is purchased.
/// use as the context object an object that you can use to remove the observer again.
- (void)addPurchasesChangedCallback:(PurchasedProductsChanged)callback withContext:(id)context;
- (void)removePurchasesChangedCallbackWithContext:(id)context;
@end