用于应用内购买测试的沙盒是否可能不适用于 iOS,因为它处于测试阶段?它在 iOS 6 模拟器和设备上工作,但在 iOS 7 模拟器或设备上不工作,不断出现无法连接到 iTunes。
代码:
- (void)purchaseRemoveAds
{
NSLog(@"ITEMS :%@", [IAPShare sharedHelper].iap.productIdentifiers);
[[IAPShare sharedHelper].iap requestProductsWithCompletion:^(SKProductsRequest* request,SKProductsResponse* response)
{
if(response > 0 ) {
NSLog(@"PRODUCTS: %@", [IAPShare sharedHelper].iap.products);
if ([[IAPShare sharedHelper].iap.products count] != 0) {
SKProduct* product =[[IAPShare sharedHelper].iap.products objectAtIndex:0];
[[IAPShare sharedHelper].iap buyProduct:product
onCompletion:^(SKPaymentTransaction* trans){
if(trans.error)
{
NSLog(@"Fail %@",[trans.error localizedDescription]);
}
else if(trans.transactionState == SKPaymentTransactionStatePurchased) {
[[IAPShare sharedHelper].iap provideContent:@"RemoveAds"];
NSLog(@"SUCCESS %@",response);
NSLog(@"Purchases %@",[IAPShare sharedHelper].iap.purchasedProducts);
[bannerView_ removeFromSuperview];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success!" message:[NSString stringWithFormat:@"You have successfully purchased %@", product.localizedTitle] delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles: nil];
[alert show];
}
else if(trans.transactionState == SKPaymentTransactionStateFailed) {
NSLog(@"Fail");
}
}];//end of buy product
}
}
}];
}