私は自分のアプリケーションのアプリ購入で使用しています。次の方法を使用して、購入した製品のトランザクションレシートを確認するためのリクエストをサーバーに送信しています。
-(void)sendingRequestForReceipt: (SKPaymentTransaction *)transaction{
networkQueue = [ASINetworkQueue queue];
[networkQueue retain];
NSString *serverUrl = @"https://sandbox.itunes.apple.com/";
NSString *receiptStr= [Base64Encoding base64EncodingForData:(transaction.transactionReceipt) WithLineLength:0];
NSString *str = [NSString stringWithFormat:@"%@verifyReceipt", serverUrl];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
NSDictionary* data = [NSDictionary dictionaryWithObjectsAndKeys:receiptStr,@"receipt-data", nil];
[request appendPostData: [[data JSONRepresentation] dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector: @selector(gotReceiptResponse:)];
[networkQueue addOperation: request];
[networkQueue go];
}
この後、次のgotReceiptResponseメソッドが呼び出されます。
- (void)gotReceiptResponse:(ASIHTTPRequest *)req{
NSString *response=[req responseString];
NSDictionary *jsonResp = [response JSONValue];
NSString *receiptValue = [jsonResp valueForKey:@"status"];
int receiptCheck=[receiptValue intValue];
if( receiptCheck ==0){
//mark item as purchased
//show alert that item was purchased and will be downloaded
UIAlertView *alert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase:"
message:@"The instrumental was purchased successfully and will now be downloaded. "
"Please do not close the app till download is complete"
delegate :self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[alert show];
[alert release];
}
}
私が応答して取得する値は、たとえば次のとおりです。 \ u009c \ u00bdFB(\ u00ffN \ u00ae \ u00a1B \ u00b7 \ u00dd \ u00ce> \ u00cd \ u00ec <6、Xcq "\ u00d6> \ u0092; \ u00ecY \ u00cb \ u009aF)\ u00a5 \ u00eb \ u00c3 \ u00e8 \ u00e0 \ u00daQ \ u00c1z \ u00f7 \ u00c2 \ u00ff \ u009bFH- \ u00a4 \ u00cc \ u00f4 \ u00f7- \ u00c4 | \ u00aax \ u00de \ u00a6 \ u00e0 \ u00fbd \ u00
\ u00e6a \ u00a2 \ u00edz \ u00bb \ u00e85 \ u00a2 \ u00e4 \ u0087 \ u00b2 \ u0096 \ u00d7 \ u00ad \ u00d0 \ u00ad \ u00d4 \ u00c5 \ u0099 \ u00dd \ u00e9 | \ u00c9 \ u00f8 u00acf \ u00c6 \ u008f \ u00d5 \ u00ef \ u00b0 \ u00fd \ u0090 \ u00ae \ u0091R \ u008f \ u00fe \ u00ed \ u00e3&}。8 / T $ \ u00a0 \ u00b4t \ u00e4 \ u00f3M \ u00f9`?
jsonRespでは、値はnullです。したがって、このユニコード文字列をエンコードする方法を知りたいだけです。取得している応答と、jsonRespのnull値の理由を理解できるようにします。