gpt4 book ai didi

iPhone 3G 4.2.1 - SKProductsRequest 委托(delegate)方法未被调用

转载 作者:行者123 更新时间:2023-11-29 11:21:10 29 4
gpt4 key购买 nike

我的应用程序 FourFourTwo Stats Zone 今晚刚刚在 App Store 上线:

我已经请一些人测试应用程序内购买并在除 iPhone 3G(运行 4.2.1 - 没有测试其他 iOS 版本)以外的所有设备上都取得了成功。我试过在我拥有的设备上调试它,似乎没有调用任何 SKProductsRequest 委托(delegate)方法。这是我的代码:

- (void)requestPurchaseOfCompetition:(Competition*)competition {
DLog("");

if ([SKPaymentQueue canMakePayments]) {
DLog(@"do store");

NSString* productIdentifier = [NSString stringWithFormat:@"%@%@_%@", kPRODUCT_IDENTIFIER_PREFIX, competition.competitionId, competition.season];

SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:productIdentifier]];

[[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationRequestProductInfo object:nil userInfo:[NSDictionary dictionaryWithObject:request forKey:@"request"]]];
request.delegate = self;
[request start];
[request release];
} else {
DLog(@"no store");

// Warn the user that purchases are disabled.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Store", @"Store") message:NSLocalizedString(@"In app purchasing is disabled for this device (in Settings > General > Restrictions). Please enable this setting to purchase more competitions.", @"In app purchasing is disabled for this device (in Settings > General > Restrictions). Please enable this setting to purchase more competitions.") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}

...

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
DLog(@"response: %@", response);
DLog(@"invalid product identifiers: %@", response.invalidProductIdentifiers);

for (SKProduct *product in response.products) {
DLog(@"product: %@", product);

[[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationGotProductInfo object:nil userInfo:[NSDictionary dictionaryWithObject:product forKey:@"product"]]];

SKPayment *payment = [SKPayment paymentWithProduct:product];

SKPaymentQueue *paymentQueue = [SKPaymentQueue defaultQueue];
[paymentQueue addTransactionObserver:self];
[paymentQueue addPayment:payment];
}
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
DLog(@"request failed: %@, %@", request, error);

[[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationRequestProductInfoFailed object:nil userInfo:[NSDictionary dictionaryWithObject:error forKey:@"error"]]];
}

- (void)requestDidFinish:(SKRequest *)request {
DLog(@"request finished: %@", request);
}

三个委托(delegate)方法中的日志消息均未出现。

这在 3GS、iPhone 4、iPad 等上运行良好,但在运行 4.2.1 的 iPhone 3G 上运行不正常。

谁能提供任何见解?

最佳答案

您不应该在开始请求后立即释放 SKProductsRequest *request,但应该在两个委托(delegate)方法中都释放它。检查the documentation对于父 SKRequest 类,它说:

When this method (requestDidFinish or request:didFailWithError:) is called, your delegate receives no further communication from the request and can release it.

我不知道为什么这在较新版本的 SDK 中对您有用,但严格查看您的代码,可能会在响应调用委托(delegate)方法之前释放请求。

我会这样做:

- (void)requestPurchaseOfCompetition:(Competition*)competition {
DLog("");

if ([SKPaymentQueue canMakePayments]) {
DLog(@"do store");

NSString* productIdentifier = [NSString stringWithFormat:@"%@%@_%@", kPRODUCT_IDENTIFIER_PREFIX, competition.competitionId, competition.season];

SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:productIdentifier]];

[[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationRequestProductInfo object:nil userInfo:[NSDictionary dictionaryWithObject:request forKey:@"request"]]];
request.delegate = self;
[request start];

} else {
DLog(@"no store");

// Warn the user that purchases are disabled.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Store", @"Store") message:NSLocalizedString(@"In app purchasing is disabled for this device (in Settings > General > Restrictions). Please enable this setting to purchase more competitions.", @"In app purchasing is disabled for this device (in Settings > General > Restrictions). Please enable this setting to purchase more competitions.") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}

...

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
DLog(@"response: %@", response);
DLog(@"invalid product identifiers: %@", response.invalidProductIdentifiers);

for (SKProduct *product in response.products) {
DLog(@"product: %@", product);

[[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationGotProductInfo object:nil userInfo:[NSDictionary dictionaryWithObject:product forKey:@"product"]]];

SKPayment *payment = [SKPayment paymentWithProduct:product];

SKPaymentQueue *paymentQueue = [SKPaymentQueue defaultQueue];
[paymentQueue addTransactionObserver:self];
[paymentQueue addPayment:payment];
}
[request release];
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
DLog(@"request failed: %@, %@", request, error);

[[NSNotificationCenter defaultCenter] postNotificationOnMainThread:[NSNotification notificationWithName:kStoreKitHandlerNotificationRequestProductInfoFailed object:nil userInfo:[NSDictionary dictionaryWithObject:error forKey:@"error"]]];
[request release];
}

关于iPhone 3G 4.2.1 - SKProductsRequest 委托(delegate)方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7071020/

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