[iOS] In App Purchase 앱에서 구매내역 확인
테스트(SandBox)와 실제 확이하는 애플 URL이 다르므로 실제 반영할 때는
변경해 주어야 한다.
내부적인 동작 과정은 서버에서 하던 클라이언트에서 하던 동일하다
transactionReceipt 를 Base64로 Encoding한 후에 'receipt-data'라는 Key에 Encoding된 transactionReceipt값을
Json 형태로 만들어 Post 방식으로 애플 확인 서버로 보내면 된다.
ASIFormDataRequest를 사용할 때는 HTTP Request부분만 아래와 같이
.
NSURL* verifyURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://sandbox.itunes.apple.com/verifyReceipt"]];
ASIFormDataRequest* request = [[[ASIFormDataRequest alloc] initWithURL:verifyURL] autorelease];
[request setRequestMethod:@"POST"];
[request appendPostData:jsonData];
[request startSynchronous];
.
.
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;
NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;
if (j < length) {
value |= (0xFF & input[j]);
}
}
NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}
return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
}
//Service URL : https://buy.itunes.apple.com/verifyReceipt
- (BOOL)verifyReceipt:(SKPaymentTransaction*)transaction
{
NSString* recieptString = [self base64forData:transaction.transactionReceipt];
NSError* error = nil;
NSDictionary* dict = [NSDictionary dictionaryWithObject:recieptString forKey:@"receipt-data"];
NSData* jsonData = [[CJSONSerializer serializer] serializeObject:dict error:&error];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://sandbox.itunes.apple.com/verifyReceipt"]]] autorelease];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonData];
NSData* responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary* jsonDict = [[CJSONDeserializer deserializer] deserializeAsDictionary:responseData error:nil];
return [[jsonDict objectForKey:@"status"] integerValue] == 0;
}
'iOS' 카테고리의 다른 글
[iOS] animateWithDuration: delay: options: animations: completion: 함수 사용 예 (0) | 2011.10.13 |
---|---|
[iOS] 외부 폰트 사용하기 (0) | 2011.10.12 |
[iOS] UIWebView 에 Bounce 효과 제거 (0) | 2011.10.10 |
[iOS] 동기적으로 동작하는 UIAlertView (Custom UIAlertView) (0) | 2011.09.28 |
[iOS] UIView 흔들기 효과 (0) | 2011.09.28 |
[iOS] 현재 시간을 GMT로 표시하기 (0) | 2011.09.20 |
[iOS] Device ID (0) | 2011.09.19 |
[iOS] 문장이 화면에 표현되는 높이와 길이 얻기 (0) | 2011.09.05 |
[iOS] UITextView를 Rounded Rect 형태로 표현하기 (0) | 2011.09.02 |
[iOS] 아이폰의 현재 상태가 세로(Portrait)인지 가로(Landscape)인지 확인하는 방법 (0) | 2011.09.02 |