RMStore requestProducts gives exception when requesting products

人盡茶涼 提交于 2019-12-24 08:50:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!