2011-08-15 6 views
1
내 애플 FourFourTwo Stats Zone 그냥 오늘 저녁에 앱 스토어에 생중계했다

: 나는에서 앱 구매를 테스트하기 위해 몇 사람을 물어에 성공있어아이폰 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); 
} 

세 대리자 메서드의 로그 메시지가 나타나지 않습니다.

이것은 3GS, iPhone 4, iPad 등에서는 잘 작동하지만 4.2.1에서는 iPhone 3G에서 작동하지 않습니다.

아무도 통찰력을 제공 할 수 있습니까?

답변

2

요청을 시작한 직후에 SKProductsRequest *request을 릴리스하면 안되지만 두 가지 대리 방법 모두에서이를 릴리스해야합니다.

이 방법 ( requestDidFinish 또는 request:didFailWithError:) 가 호출

, 당신의 대리자를 요청에서 더 이상 통신을 수신하지 그것을 해제 할 수 있습니다 : 부모에 대한 the documentation 말한다 SKRequest 클래스를 확인합니다.

최신 버전의 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

감사 @Matej Balantič 같은 일이하고 수정 좋았어요. –

관련 문제