vendredi 29 juin 2018

In app purchase live url show sandbox popup and allow subscription for sandbox user

I have added in-app purchase in my application it is working well in sandbox environment but when I change it's URL from sandbox to live and run the application it is behaving unexpectedly.

Here is my code:

Below are the method in which we are requesting to apple for getting in app purchase detail of user.

-(BOOL) getSubscriptionStatusFromAppleWithReceipt:(NSData *) receiptData

{

NSError *error;
NSMutableDictionary *requestContents = [NSMutableDictionary dictionaryWithObject:
                                        [receiptData base64EncodedStringWithOptions:0] forKey:@"receipt-data"];
NSString *sharedSecret = @“*********************”;
if (sharedSecret) requestContents[@"password"] = sharedSecret;
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents options:0 error:&error];

NSString *strUrl = @"";


// Live server
strUrl = @"https://buy.itunes.apple.com/verifyReceipt";

// Devlopment server

// strUrl = @"https://sandbox.itunes.apple.com/verifyReceipt";

NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strUrl]];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];

queue = [NSOperationQueue mainQueue];

//    NSError *error = nil; 
NSHTTPURLResponse *response = nil;

NSData *data = [NSURLConnection sendSynchronousRequest:storeRequest returningResponse:&response error:&error];

if (!error)
{
    NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

    if ([jsonResponse[@"latest_receipt_info"] isKindOfClass:[NSArray class]])
    {
        NSArray *receiptInfo = (NSArray *) jsonResponse[@"latest_receipt_info"];
        return [self parseJsonFromAppleServer:receiptInfo];
    }
}
else
{        NSLog(@"%@", error.localizedDescription);
}

return false;   

}

And next method in this I m retrieving the last index of receipt array and try to get user's subscription details.

Should I upload it on test flight or any other way in it's differentiation from live to development? How to test it in live environment.

Thanks

Aucun commentaire:

Enregistrer un commentaire