2016-11-15 4 views
1

私は有料から無料への変換に取り組んでいます。以前の機能の一部はIAPの下にあります。その結果、既存のユーザーはIAPのコピーを取得する必要があります。これを行うために、Apple's Websiteからの領収書検証コードを使用しています。この場合の私の目標は、正当性の領収書を実際に検証するのではなく、ユーザーが購入したバージョン番号を返すようになっているからです。彼らが有料ユーザーであるかどうかを検出できます(提案についてはthis questionありがとうございます)。この場合、領収書の検証をテストするにはどうすればよいですか?

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; 
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL]; 
if (!receipt) { NSLog(@"No receipt found"); return; } 

これは、ユーザーの領収書を取得するために使用しているコードです。これは、上記公式リンゴサイトのコードとほぼ同じです。しかし、私はまだそれとそれに続くコードをテストしたいと思います。これはユーザーにIAPを許可します。

ただし、上記のコードでは、「受信確認なし」と表示され、Simulator、Xcode経由のiPhone、またはTestFlight経由でiPhoneでプログラムを実行すると返されます。私は現在のApp Storeのバージョンをインストールしてから、TestFlightを試しましたが、それでも同じ受信不能エラーが発生しました。

テストの領収書のコピーを取得するにはどうしたらいいですか?また、この形式のレシート検証をどのようにテストしますか?

+0

。 – Paulw11

答えて

2

SKReceiptRefreshRequestは偽の領収書を提供します。この偽の領収書は、Appleのサンドボックス検証サーバーで検証します。 SKReceiptRefreshRequestを呼び出すことは私が欠けていた要素でした。

SKReceiptRefreshRequest *receiptRequest = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil]; 
receiptRequest.delegate = self; 
[receiptRequest start]; 

- 限り私はあなたがサンドボックス内でIAPを完了するまでのdevのビルドが利用できる領収書を持っていないことを知っているよう

- (void)requestDidFinish:(SKRequest *)request { 
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; 
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL]; 
if (!receipt) { NSLog(@"No receipt found"); return; } 
// Create the JSON object that describes the request 
NSError *error; 
NSDictionary *requestContents = @{ 
            @"receipt-data": [receipt base64EncodedStringWithOptions:0] 
            }; 
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents 
                 options:0 
                 error:&error]; 

if (!requestData) { NSLog(@"No request data found"); return; } 

// Create a POST request with the receipt data. 
NSURL *storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"]; 
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL]; 
[storeRequest setHTTPMethod:@"POST"]; 
[storeRequest setHTTPBody:requestData]; 
// Make a connection to the iTunes Store on a background queue. 
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue 
         completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 
          if (connectionError) { 
           NSLog(@"Connection error"); 
           return; 
          } else { 
           NSError *error; 
           NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; 
           if (!jsonResponse) { return; } 
           NSLog(@"JsonResponce: %@",jsonResponse); 
           NSString *version = jsonResponse[@"receipt"][@"original_application_version"]; 
           //found version number! Do whatever with it! 
          } 
         }]; 
関連する問題