Develop
2013.11.20 13:16
[ios] iOS In App Purchase 코드 부분 샘플 2
조회 수 11284 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
229 | Develop | [c] 디피-헬만 키교환(Diffie–Hellman key exchange) 샘플 코드.. ㅋㄷ | hooni | 2013.04.23 | 9111 |
228 | Develop | [mysql] 양력, 음력 DB데이터 | hooni | 2013.04.23 | 7802 |
227 | Develop | [c] 파일(int fd)에서 개행문자 단위로 읽기 by 후리자 | hooni | 2013.04.23 | 7152 |
226 | Develop | [c] 지폰(gphone) 소스.. 수정(암호화) | hooni | 2013.04.23 | 7434 |
225 | Develop | [c] 암호 알고리즘 소스.. | hooni | 2013.04.23 | 8342 |
224 | Develop | [c] 시스템 보안 과제.. 시간(amc time) 변경 | hooni | 2013.04.23 | 7194 |
223 | Develop | [switch] 시스코 카탈리스트(Cisco Catalyst) 2950 미러링 설정 | hooni | 2013.04.23 | 11392 |
222 | Develop | [c] 네트워크 보안 프로그래밍 과제 (Server,Agent,Client) | hooni | 2013.04.23 | 6473 |
221 | Develop | [php] 탐색기와 같은 다이나믹 트리(xml/xsl 이용) | hooni | 2013.04.23 | 7154 |
220 | Develop | [js] 스타크래프트(starcraft).. | hooni | 2013.04.23 | 6641 |
219 | Develop | [js] 툴팁.. 좋은거.. (tooltip) | hooni | 2013.04.23 | 7059 |
218 | Develop | [web] URL 인코딩 방법.. 테이블.. ㅋㅋ | hooni | 2013.04.23 | 7143 |