Contents

조회 수 11266 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

쿠드 구현 부분..

이 샘플이 설명이 더 자세한 듯..

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



?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
» Develop [ios] iOS In App Purchase 코드 부분 샘플 2 hooni 2013.11.20 11266
812 Develop [ios] iOS In App Purchase 코드 부분 샘플 1 hooni 2013.11.20 11750
811 Develop [ios] iOS In App Purchase #2 (코드 구현) file hooni 2013.11.20 13758
810 Develop [ios] iOS In App Purchase #1 (코드 구현 전 웹 설정 작업) file hooni 2013.11.20 14500
809 Develop [ios] iphone SetDeviceOrientation 화면 강제 회전 hooni 2013.11.20 18449
808 Develop [js] window.open() 속성 사용 방법 hooni 2013.11.18 13579
807 Develop [php] php5.3부터는 eregi()대신 preg_match()를 사용 hooni 2013.11.18 12459
806 Develop [java] 초간단 싱글톤(Singleton) 패턴 샘플 코드 file hooni 2013.11.18 11585
805 [ios] 인앱결제 & 오토레이아웃 관련 강좌 secret hooni 2013.11.14 0
804 Etc [NFC] 단말기와 서버 통신 내용 hooni 2013.11.12 11175
803 Develop [python] 파이썬 공부하는 사이트~ hooni 2013.11.12 10827
802 System/OS [mac] Charlesproxy 간단한 설정 내용~ hooni 2013.11.12 12314
Board Pagination Prev 1 ... 26 27 28 29 30 31 32 33 34 35 ... 98 Next
/ 98