Я включил автоматическое обновление ежемесячной подписки в приложении в своем приложении.Я получаю квитанцию Apple, позвонив в песочницу по URL iTunes.Моя проблема в том, что моя подписка с автоматическим продлением не истекла через 5 минут.
Я не смог автоматически обновить его в своем iPhone.Пожалуйста, предложите, как я могу проверить покупки в приложении в среде песочницы.
Вот мой код:
Здесь мы призываем к получению яблок.
-(BOOL) getSubscriptionStatusFromAppleWithReceipt:(NSData *) receiptData
{
NSError *error;
NSMutableDictionary *requestContents = [NSMutableDictionary dictionaryWithObject:
[receiptData base64EncodedStringWithOptions:0] forKey:@"receipt-data"];
NSString *sharedSecret = @"efd594143c2840bdac89fc22eccd3a3d";
if (sharedSecret) requestContents[@"password"] = sharedSecret;
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents options:0 error:&error];
NSString *strUrl = @"";
// set 1 in AppConstant.h for Live enviorment
if (kPARSE_DEVELOPMENT_SERVER) {
// Production
strUrl = @"https://buy.itunes.apple.com/verifyReceipt";
}
else{
// Sandbox
strUrl = @"https://sandbox.itunes.apple.com/verifyReceipt";
}
//Chandni commented live server url
// 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];
// NSLog(@"%@", newStr);
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
// NSLog(@"%@", jsonResponse[@"latest_receipt_info"]);
if ([jsonResponse[@"latest_receipt_info"] isKindOfClass:[NSArray class]])
{
NSArray *receiptInfo = (NSArray *) jsonResponse[@"latest_receipt_info"];
return [self parseJsonFromAppleServer:receiptInfo];
}
}
else
{
NSString *strTemp = @" \n Database getSuscriptionStatus error in api calling of apple ";
NSLog(@"%@", error.localizedDescription);
}
return false;
}
-(BOOL) parseJsonFromAppleServer:(NSArray *) receiptInfo
{
if (receiptInfo.count > 0)
{
id lastReceipt = [receiptInfo lastObject];
if ([lastReceipt isKindOfClass:[NSDictionary class]])
{
NSDictionary *dictLastReceipt = (NSDictionary *) lastReceipt;
NSString *lastPurchase = [dictLastReceipt valueForKey:@"product_id"];
NSString *secondLastPurchase = @""; // In case if users last inapp is Removal of Advertisement
if (receiptInfo.count > 1) {
id secondLastReceipt = receiptInfo[receiptInfo.count - 2];
if ([secondLastReceipt isKindOfClass:[NSDictionary class]])
{
NSDictionary *dictSecondLastReceipt = (NSDictionary *) secondLastReceipt;
secondLastPurchase = [dictSecondLastReceipt valueForKey:@"product_id"];
}
}
if ([lastPurchase isEqualToString:@"com.divorcecommunity.monthly"] || [secondLastPurchase isEqualToString:@"com.divorcecommunity.monthly"])
{
NSString *strExpirationDate = [dictLastReceipt valueForKey:@"expires_date_pst"];
NSDate *expirationDate = [CommonUtilities getExpirationDateFromDateString:strExpirationDate];
[[NSUserDefaults standardUserDefaults] setObject:expirationDate forKey:@"ExpirationDate"];
NSDate *serverDate = [[AppDelegate sharedAppDelegate] serverDate];
NSString *strExpirateDate = [CommonUtilities getStringDateFromDate:expirationDate];
NSString *strServerDate = [CommonUtilities getStringDateFromDate:serverDate];
NSDate *dateExpiration = [CommonUtilities getDateFromDateString:strExpirateDate havingDateFormat:@"yyyy-MM-dd"];
NSDate *dateServer = [CommonUtilities getDateFromDateString:strServerDate havingDateFormat:@"yyyy-MM-dd"];
// CS Save data in default for reciept
[[NSUserDefaults standardUserDefaults] setObject:receiptInfo forKey:@"AppleReciept"];
[[NSUserDefaults standardUserDefaults] setObject:serverDate forKey:@"ServerDate"];
[[NSUserDefaults standardUserDefaults] setObject:expirationDate forKey:@"ExpirationDate"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSInteger daysDifference = [CommonUtilities getDifferenceBetweenStartDate:dateServer andEndDate:dateExpiration];
NSInteger daysRemainingInExpiration = [[CommonUtilities sharedManager] getMinDifferenceBetweenStartDate:serverDate andEndDate:expirationDate];
NSLog(@"Subscription expires +ve or -ve %ld",(long)daysRemainingInExpiration);
if (daysRemainingInExpiration >= 0)
{
[self saveNewInAppOfType:lastPurchase withExpirationDate:expirationDate];
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
return false;
}
Есть какие-либоу кого-нибудь есть решение, тогда, пожалуйста, поделитесь.
Спасибо