iPhone 3G 4.2.1 - SKProductsRequest 委托方法未被调用
我的应用 FourFourTwo Stats Zone 刚刚上线今晚在 App Store 中:
我请了几个人测试应用内购买,并在除 iPhone 3G(运行 4.2.1 - 还没有)之外的所有设备上都取得了成功与其他 iOS 版本进行了测试)。我尝试在我拥有的设备上调试它,似乎没有调用任何 SKProductsRequest 委托方法。这是我的代码:
- (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);
}
三个委托方法中都没有出现日志消息。
这在 3GS、iPhone 4、iPad 等设备上运行良好,但在运行 4.2.1 的 iPhone 3G 上运行不佳。
任何人都可以提供任何见解吗?
My app FourFourTwo Stats Zone has just went live in the App Store this evening:
I've asked a few people to test the In App Purchase and got successes on all devices except the iPhone 3G (running 4.2.1 - haven't tested with other iOS versions). I've tried debugging it on a device I have and it seems that none of the SKProductsRequest delegate methods are being called. Here's my code:
- (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);
}
None of the log messages in the three delegate methods are appearing.
This works fine on 3GS, iPhone 4, iPad etc but not on the iPhone 3G running 4.2.1.
Can anyone provide any insight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应在启动请求后立即释放
SKProductsRequest *request
,而应在两个委托方法中释放它。检查父 文档 < code>SKRequest 类表示:我不知道为什么这在较新版本的 SDK 中对您有效,但严格查看您的代码,请求可能会在响应调用委托方法之前被释放。
我就是这样做的:
You shouldn't release
SKProductsRequest *request
right after you start the request, but should have released it in both delegate methods. Check the documentation for parentSKRequest
class which says:I don't know why this worked for you in newer versions of SDK, but strictly looking at your code, request could potentially be released before the response could have invoked the delegate methods.
This is how I would do it: