I pretty much follow Ray Wenderlich's example for doing In-App purchases. This includes that I get my product information first from a server. In my case I use Amazon Web Services.
The problem I have is that [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
is not working, which means that - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
is not being called.
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
gets called within the _productIDCompletionHandler
block.
I have narrowed it down to the following code. As long as I call [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
before continueWithExecutor the observer works. If I call the addTransactionObserver within the BFTask block or after, then updatedTransactions method is not being called.
-(void)getProductidsWithCompletionHandler:(AWSAccessProductIDsCompletionHandler)completionHandler {
_productIDCompletionHandler = [completionHandler copy];
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
// Construct the NSURL for the download location.
NSString *downloadingFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"aws_downloadedproductidfile"];
NSURL *downloadingFileURL = [NSURL fileURLWithPath:downloadingFilePath];
// Construct the download request.
AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];
downloadRequest.bucket = [self bucketStringForType:WB_com_test];
downloadRequest.key = [NSString stringWithFormat:@"%@%@",COM_PRODUCTIDS_FILEPATH,COM_PRODUCTIDS_FILENAME];
downloadRequest.downloadingFileURL = downloadingFileURL;
[[transferManager download:downloadRequest] continueWithExecutor:[BFExecutor mainThreadExecutor]
withBlock:^id(BFTask *task) {
if (task.error){
NSLog(@"Error: %@", task.error);
_productIDCompletionHandler(NO,nil);
_productIDCompletionHandler = nil;
}
if (task.result) {
NSLog(@"Success: ");
AWSS3TransferManagerDownloadOutput *output = task.result;
NSURL *url = (NSURL *)output.body;
NSArray *products = [NSArray arrayWithContentsOfURL:url];
DDLogVerbose(@"Success Result Count: %lu", (unsigned long)[products count]);
if (products)
{
_productIDCompletionHandler( YES, products);
} else
{
_productIDCompletionHandler( NO, nil);
}
_productIDCompletionHandler = nil;
}
return nil;
}];
}
When the above _productIDCompletionHandler handler returns it is on the main thread so this is not the problem, but somehow the thread is "dirty".
Aucun commentaire:
Enregistrer un commentaire