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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
753 | Develop | [ios] IB 없이 개발하기 (html) | hooni | 2013.05.31 | 0 |
752 | System/OS | [mysql] MySQL server has gone away 에러 대응 | hooni | 2013.05.29 | 19226 |
751 | PPT | [Android] 제스처 자료.. | hooni | 2013.05.28 | 51075 |
750 | PPT | [doc] BHO관련 발표 자료(디펜스에 쓸꺼) | hooni | 2013.05.28 | 0 |
749 | Develop | [iphone] PerfectlyClear 보정솔루션 최신.. | hooni | 2013.05.28 | 0 |
748 | Etc | 논문(BHO)에 들어갈 내용 집에가서 테스트 해볼 것.. | hooni | 2013.05.28 | 10230 |
747 | PPT | 네오웹 세미나 자료~ | hooni | 2013.05.28 | 0 |
746 | Develop | [Android] 2010년에 만들었던 세미나 자료. | hooni | 2013.05.28 | 64663 |
745 | Develop | [js] 자바스크립트의 클로저 (JavaScript's Closure) | hooni | 2013.05.15 | 12979 |
744 | Develop | 서기의 PHP 동영상 강의(싱싱해) | hooni | 2013.05.15 | 30982 |
743 | Etc | 영어공부에 도움될만한 사이트 모음 | hooni | 2013.05.14 | 22632 |
742 | System/OS | Mac OS X - Apache+PHP+MySQL 환경 서버 | hooni | 2013.04.25 | 31629 |