gpt4 book ai didi

objective-c - Apple month autorenew 沙盒订阅不会在 5 分钟内过期并且不会在 apple receipt 中收到数据

转载 作者:行者123 更新时间:2023-11-28 20:49:55 24 4
gpt4 key购买 nike

我在我的应用程序中实现了自动续订每月订阅应用程序内购买。我通过调用 iTunes 的沙箱 URL 获得苹果收据。我的问题是我的自动续订订阅在 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;
}

有没有人有解决办法,请分享。

谢谢

最佳答案

在沙盒环境中测试 1 个月的苹果订阅时,收据似乎会自动续订大约六次(理论上)。有时我注意到收据会在五分钟后过期,有时则需要 30 分钟(自动续订六次)。

关于objective-c - Apple month autorenew 沙盒订阅不会在 5 分钟内过期并且不会在 apple receipt 中收到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50837299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com