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

发布于 2024-11-29 20:53:21 字数 3147 浏览 1 评论 0原文

我的应用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别在捏我脸啦 2024-12-06 20:53:21

您不应在启动请求后立即释放 SKProductsRequest *request,而应在两个委托方法中释放它。检查父 文档 < code>SKRequest 类表示:

当此方法(requestDidFinishrequest:didFailWithError:)时
被呼叫时,您的代表不会收到来自
请求并可以释放它。

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

我就是这样做的:

- (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];
}

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 parent SKRequest class which says:

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

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:

- (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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文