프로그래밍/예전글
아이폰 개발 - In app purchase, store kit
Cat체셔
2012. 1. 13. 17:01
헤더파일 : StoreKit/StoreKit.h
라이브러리파일 : StoreKit.framework
딜리게이트 : SKProductsRequestDelegate
상품 요청
SKProductsRequest *preq = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PRODUCT_ID]];
preq.delegate = self;
[preq start];
- PRODUCT_ID : In app purchase에 등록한 상품 아이디를 입력하시면 됩니다.
ex)com.sadun.app.item1
상품 요청에 대한 응답
-(void)productsRequest(SKProductsRequest*)req didReceiveResponse:(SKProductsResponse*)response
{
if([response.products count] >0)
{
for( SKProduct* product in response.products )
{
SKPayment *pPayment = [SKPayment paymentWithProduct:product];
NSLog(@"Title:%@", product.localizedTitle);
NSLog(@"Description:%@", product.localizedDescription);
NSLog(@"Price:%@", product.price);
[[SKPaymentQueue defaultQueue] addPayment:pPaymen];
}
}
if([response.invalidProductIdentifiers count] > 0)
{
printf("find invalid product\n");
for(NSString* invalidString in [response invalidProductIdentifiers])
{
NSLog(@"Invalid Identifiers:%@", invalidString);
}
}
[req autorelease];
}
결제 후 처리
-(void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions
{
for( SKPaymentTransaction* tran in transactions )
{
switch( tran.transactionState )
{
case SKPaymentTransactionStatePurchasing:
/*----------------------------------------
구매 중 처리
----------------------------------------*/
break;
case SKPaymentTransactionStatePurchased:
/*----------------------------------------
구매 후 처리
----------------------------------------*/
break;
case SKPaymentTransactionStateRestored:
/*----------------------------------------
이미 구매 됨 처리
----------------------------------------*/
break;
case SKPaymentTransactionStateFailed:
/*----------------------------------------
구매 실패 처리
----------------------------------------*/
break;
default:
break;
}
}
}
라이브러리파일 : StoreKit.framework
딜리게이트 : SKProductsRequestDelegate
상품 요청
SKProductsRequest *preq = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PRODUCT_ID]];
preq.delegate = self;
[preq start];
- PRODUCT_ID : In app purchase에 등록한 상품 아이디를 입력하시면 됩니다.
ex)com.sadun.app.item1
상품 요청에 대한 응답
-(void)productsRequest(SKProductsRequest*)req didReceiveResponse:(SKProductsResponse*)response
{
if([response.products count] >0)
{
for( SKProduct* product in response.products )
{
SKPayment *pPayment = [SKPayment paymentWithProduct:product];
NSLog(@"Title:%@", product.localizedTitle);
NSLog(@"Description:%@", product.localizedDescription);
NSLog(@"Price:%@", product.price);
[[SKPaymentQueue defaultQueue] addPayment:pPaymen];
}
}
if([response.invalidProductIdentifiers count] > 0)
{
printf("find invalid product\n");
for(NSString* invalidString in [response invalidProductIdentifiers])
{
NSLog(@"Invalid Identifiers:%@", invalidString);
}
}
[req autorelease];
}
결제 후 처리
-(void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray*)transactions
{
for( SKPaymentTransaction* tran in transactions )
{
switch( tran.transactionState )
{
case SKPaymentTransactionStatePurchasing:
/*----------------------------------------
구매 중 처리
----------------------------------------*/
break;
case SKPaymentTransactionStatePurchased:
/*----------------------------------------
구매 후 처리
----------------------------------------*/
break;
case SKPaymentTransactionStateRestored:
/*----------------------------------------
이미 구매 됨 처리
----------------------------------------*/
break;
case SKPaymentTransactionStateFailed:
/*----------------------------------------
구매 실패 처리
----------------------------------------*/
break;
default:
break;
}
}
}