2011-08-15 9 views
1
マイアプリ FourFourTwo Stats Zoneはちょうどこの夜App Storeでライブを行ったた

:私はアプリ内購入をテストするために少数の人々を求め、上の成功を持っているiPhone 3Gの4.2.1 - SKProductsRequestのデリゲートメソッドが呼び出されていない

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); 
} 

3つのデリゲートメソッドのログメッセージは表示されません。

これは3GS、iPhone 4、iPadなどでは正常に動作しますが、iPhone 3Gでは4.2.1では動作しません。

誰でも洞察力を提供できますか?

答えて

2

要求を開始した直後にSKProductsRequest *requestを解放する必要はありませんが、どちらの委任方法でも解放してください。

をこの方法(requestDidFinishまたはrequest:didFailWithError:) が呼び出されると、デリゲートは 要求からそれ以上の通信を受信しないし、それを解放することができます言う親SKRequestクラスのthe documentationを確認してください。

新しいバージョンの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]; 
} 
+0

おかげ@MatejBalantič同じことが起こったと、あなたの修正が素晴らしかったです。 –

関連する問題