Develop
2013.11.20 13:16
[ios] iOS In App Purchase 코드 부분 샘플 2
조회 수 11272 댓글 0
쿠드 구현 부분..
이 샘플이 설명이 더 자세한 듯..
storekit.framework를 추가 후 소스코드(.h/.m)에 대한 설명임.
# 헤더 파일 내용
#import <UIKit/UIKit.h> #import <StoreKit/StoreKit.h> //스토어킷 프레임워크 추가해주시구요. /* 아래 delegate를 지정해야 함. SKProductsRequestDelegate : 상품정보 획득에 사용 SKPaymentTransactionObserver : 상품 구매에 관련(구입성공,실패,재구입 등 구매 트랜잭션) */ @interface iAPTest : UIViewController <SKProductsRequestDelegate, SKPaymentTransactionObserver> { } @end
# 코드 내용
#import "iAPTest.h" #import <StoreKit/StoreKit.h> // 각자의 판매아이템들에 대한 고유한 값이며 // Manage In App Purchase에서 등록한 값으로 설정하면 됨. #define kProductId1 @"com.iAPtest.item1" #define kProductId2 @"com.iAPtest.item2" #define kProductId3 @"com.iAPtest.item3" @implementation iAPTest - (void)viewDidLoad { //아래의 코드를 추가하여 구매 관련 이벤트를 자신이 처리하겠다고 지정. [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; } //선택된 아이템에 대한 정보를 획득하여 표시해줄 때 사용. -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{ for(SKProduct *product in response.products){ /* localizedDescription //아이템 설명 localizedTitle //아이템 이름 price //아이템 가격 priceLocale //지역별 가격표시 ex) $,원 표시등.. productIdentifier //제품식별코드 아래와 같이 product.xxxxx 로 접근해서 화면에 뿌려주면 될 듯. product.localizedTitle */ } [request release]; } //아래 매소드는 해당 아이템의 버튼을 클릭했을 시 연결되는 부분. //각각의 버튼에 구매될 아이템의 정보를 서버로 부터 얻어와서 해당 제품ID 순으로 정렬하고 //버튼 이벤트를 아래 메소드에 연결해서 0번째는 0번째 아이템, 1번째는 1번째 아이템 순으로 연결 //여기에 대한 내용은 각자의 입맛에 맛게^_^; -(void)buyitem:(id)sender{ SKPayment *payment; SKProductsRequest *request; UIButton *button = (UIButton *)sender; NSInteger tags = button.tag; if(tags==0){ // 선택된 아이템의 구매정보를 입력합니다. payment = [SKPayment paymentWithProductIdentifier:kProductId1]; /* // 선택된 아이템의 정보를 요청합니다. request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kProductId1]]; */ }else if(tags==1){ payment = [SKPayment paymentWithProductIdentifier:kProductId2]; }else{ payment = [SKPayment paymentWithProductIdentifier:kProductId3]; } request.delegate=self; //아래의 코드에서 선택된 제품의 정보를 요청하고, 구매요청을 합니다. //[request start]; [[SKPaymentQueue defaultQueue] addPayment:payment]; } -(void)purchasedTransaction:(SKPaymentTransaction *)transaction{ /* . . 원하는 기능 추가. . */ [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; } -(void)restoreTransaction:(SKPaymentTransaction *)transaction{ /* . . 원하는 기능 추가. . */ [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; } -(void)failedTransaction:(SKPaymentTransaction *)transaction{ /* . . 원하는 기능 추가. . */ [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; } - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ for(SKPaymentTransaction *transaction in transactions){ switch(transaction.transactionState) { case SKPaymentTransactionStatePurchased: //구매완료. [self purchasedTransaction:transaction]; break; case SKPaymentTransactionStateFailed: //구매실패. [self failedTransaction:transaction]; break; case SKPaymentTransactionStateRestored: //재구매, [self restoreTransaction:transaction]; break; default: break; } } } @end
[출처] http://cafe.naver.com/mcbugi/75067
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
813 | System/OS | [linux] root 전환시 패스워드 없이 su 사용하기 | hooni | 2013.12.22 | 12681 |
812 | Database | [mysql] error while loading shared libraries: libmysqlclient.so.10: | hooni | 2003.04.23 | 12663 |
811 | Develop | [c++] Win32 API 기본 출력인 MessageBox() 함수 사용 예제.. | hooni | 2013.04.23 | 12623 |
810 | System/OS | [linux] 간단한 NAT 설정 script | hooni | 2003.04.23 | 12593 |
809 | Etc | [flash] 맘에 드는 파이차트 | hooni | 2013.04.23 | 12590 |
808 | Database | [sql] 간단한 SQL 문법 정리 | hooni | 2003.04.23 | 12551 |
807 | PPT | [ppt] 네오웹 소프트.. 발표 자료 모음 | hooni | 2003.04.23 | 12550 |
806 | System/OS | [doc] 피쳐셀렉션(feature selection using..) 발표 자료 | hooni | 2013.04.23 | 12546 |
805 | PPT | [doc] 위탁과제 제안서와 발표자료(pdf) | hooni | 2013.04.23 | 12534 |
804 | System/OS | [linux] 스케쥴링 순서(nice) 변경하기 | hooni | 2003.04.23 | 12532 |
803 | Develop | [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 | hooni | 2003.04.23 | 12488 |
802 | Develop | [ios] 네트워크 인디케이터(NetworkActivityIndicator) 작동 | hooni | 2014.01.24 | 12486 |