|
@@ -9,7 +9,7 @@
|
|
|
@interface IAPWrapper () <SKProductsRequestDelegate, SKPaymentTransactionObserver>
|
|
@interface IAPWrapper () <SKProductsRequestDelegate, SKPaymentTransactionObserver>
|
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, SKProduct *> *products;
|
|
@property(nonatomic, strong) NSMutableDictionary<NSString *, SKProduct *> *products;
|
|
|
@property(nonatomic, strong) SKProductsRequest *productsRequest;
|
|
@property(nonatomic, strong) SKProductsRequest *productsRequest;
|
|
|
-@property(nonatomic, strong) NSDictionary *initRequest;
|
|
|
|
|
|
|
+@property(nonatomic, strong) NSDictionary *catalogRequest;
|
|
|
@property(nonatomic, strong) NSDictionary *purchaseRequest;
|
|
@property(nonatomic, strong) NSDictionary *purchaseRequest;
|
|
|
@property(nonatomic, strong) NSDictionary *restoreRequest;
|
|
@property(nonatomic, strong) NSDictionary *restoreRequest;
|
|
|
@property(nonatomic, strong) NSMutableArray *restored;
|
|
@property(nonatomic, strong) NSMutableArray *restored;
|
|
@@ -79,7 +79,7 @@
|
|
|
for (id value in ids) if (![value isKindOfClass:NSString.class] || ![value length]) {
|
|
for (id value in ids) if (![value isKindOfClass:NSString.class] || ![value length]) {
|
|
|
[self reply:r data:nil error:@"商品 ID 必须为非空字符串。"]; return;
|
|
[self reply:r data:nil error:@"商品 ID 必须为非空字符串。"]; return;
|
|
|
}
|
|
}
|
|
|
- self.initRequest = r;
|
|
|
|
|
|
|
+ self.catalogRequest = r;
|
|
|
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:ids]];
|
|
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:ids]];
|
|
|
self.productsRequest.delegate = self;
|
|
self.productsRequest.delegate = self;
|
|
|
[self.productsRequest start];
|
|
[self.productsRequest start];
|
|
@@ -127,15 +127,15 @@
|
|
|
@"description": product.localizedDescription ?: @"", @"price": product.price.stringValue,
|
|
@"description": product.localizedDescription ?: @"", @"price": product.price.stringValue,
|
|
|
@"localizedPrice": [formatter stringFromNumber:product.price] ?: @"", @"currencyCode": formatter.currencyCode ?: @""}];
|
|
@"localizedPrice": [formatter stringFromNumber:product.price] ?: @"", @"currencyCode": formatter.currencyCode ?: @""}];
|
|
|
}
|
|
}
|
|
|
- [self reply:self.initRequest data:@{@"products": items, @"invalidProductIds": response.invalidProductIdentifiers} error:nil];
|
|
|
|
|
- self.initRequest = nil; self.productsRequest = nil;
|
|
|
|
|
|
|
+ [self reply:self.catalogRequest data:@{@"products": items, @"invalidProductIds": response.invalidProductIdentifiers} error:nil];
|
|
|
|
|
+ self.catalogRequest = nil; self.productsRequest = nil;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
|
|
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
if (request != self.productsRequest) return;
|
|
if (request != self.productsRequest) return;
|
|
|
- [self reply:self.initRequest data:nil error:error.localizedDescription];
|
|
|
|
|
- self.initRequest = nil; self.productsRequest = nil;
|
|
|
|
|
|
|
+ [self reply:self.catalogRequest data:nil error:error.localizedDescription];
|
|
|
|
|
+ self.catalogRequest = nil; self.productsRequest = nil;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
|
|
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
|