#import "InAppPurchase.h"
#import "VerifyStoreReceipt.h"
@implementation InAppPurchase
- (void)requestPurchasing:(NSString *)productID
{
if (![SKPaymentQueue canMakePayments]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"エラー"
message:@"アプリ内課金が制限されています。"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
return;
}
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
NSSet *productIDs = [NSSet setWithObject:productID];
SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIDs];
productRequest.delegate = self;
[productRequest start];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
for (SKProduct *product in response.products) {
// NSLog(@"Product %@", product.productIdentifier);
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
NSLog(@"*****1");
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
{
// 購入中の処理
break;
}
case SKPaymentTransactionStatePurchased:
{
// 購入成功時の処理
[queue finishTransaction:transaction];
// NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
// NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
NSLog(@"*****2");
UserData::getInstance()->addItem(ItemFever, 1);
break;
}
case SKPaymentTransactionStateRestored:
{
// リストア時の処理
[queue finishTransaction:transaction];
break;
}
case SKPaymentTransactionStateFailed:
default:
// 購入失敗時の処理
[queue finishTransaction:transaction];
break;
}
}
}
@end