我正在尝试在一个应用程序中实现 IAP,但我仍然遇到困难。我遵循了各种教程,但它们都已经过时并且充满了错误。我发现唯一可以工作的是这个:
但是我遇到了一个问题,这 3 个产品出现在我的 tableview 上,但是当我点击其中一个时,什么也没有发生……单元格变成蓝色,仅此而已……我错过了什么吗?
还是那个教程不完整?
如何运行购买尝试?
这是我的代码:
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
[productDetailsList addObjectsFromArray: response.products];
[productDisplayTableView reloadData];
}
-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.productDetailsList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *GenericTableIdentifier = @"GenericTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: GenericTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: GenericTableIdentifier];
}
NSUInteger row = [indexPath row];
SKProduct *thisProduct = [productDetailsList objectAtIndex:row];
[cell.textLabel setText:[NSString stringWithFormat:@"%@ - %@", thisProduct.localizedTitle, thisProduct.price]];
return cell;
}
- (void)viewDidLoad
{
productDetailsList = [[NSMutableArray alloc] init];
productIdentifierList = [[NSMutableArray alloc] init];
for (short item_count=1; item_count <= 5; item_count++) {
[productIdentifierList addObject:[NSString stringWithFormat:@"com.mycompany.myapp.%d", item_count]];
}
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:productIdentifierList]];
request.delegate = self;
[request start];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}