问题
I am using RMStore library for IAP (subscription based) and I get exception at this line: [[RMStore defaultStore] requestProducts:[NSSet setWithArray:_products] success:^(NSArray *products, NSArray *invalidProductIdentifiers) {
- (void)viewDidLoad
{
[super viewDidLoad];
_products = @[@"NEWSUB01",
@"NEWSUB06",
@"NEWSUB12"];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[[RMStore defaultStore] requestProducts:[NSSet setWithArray:_products] success:^(NSArray *products, NSArray *invalidProductIdentifiers) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
_productsRequestFinished = YES;
} failure:^(NSError *error) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Products Request Failed", @"")
message:error.localizedDescription
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alertView show];
}];
}
below is the requestProducts function and the exception is at line: [_productsRequestDelegates addObject:delegate];
- (void)requestProducts:(NSSet*)identifiers
success:(RMSKProductsRequestSuccessBlock)successBlock
failure:(RMSKProductsRequestFailureBlock)failureBlock
{
RMProductsRequestDelegate *delegate = [[RMProductsRequestDelegate alloc] init];
delegate.store = self;
delegate.successBlock = successBlock;
delegate.failureBlock = failureBlock;
[_productsRequestDelegates addObject:delegate];
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers];
productsRequest.delegate = delegate;
[productsRequest start];
}
Same code works in a sample app but does not work in my app.
回答1:
One thing I noticed that the sample project in RMStore is using non-renewable IAP. For auto-renewable subscription based IAP you should set your store as below:
const BOOL iOS7OrHigher = floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1;
_receiptVerifier = iOS7OrHigher ? [[RMStoreAppReceiptVerifier alloc] init] : [[RMStoreTransactionReceiptVerifier alloc] init];
[RMStore defaultStore].receiptVerifier = _receiptVerifier;
_persistence = [[RMStoreUserDefaultsPersistence alloc] init];
[RMStore defaultStore].transactionPersistor = _persistence;
Use RMStoreUserDefaultsPersistence for persistence of transaction and also when you refresh or call the receipt it will be persisted automatically according to the documentation of RMStore. Check at the end of the page at the link.
来源:https://stackoverflow.com/questions/42433636/rmstore-requestproducts-gives-exception-when-requesting-products