2012-12-06 52 views
0

我想處理在沒有互聯網連接的情況下請求應用內購買產品的情況。SKProductRequest在沒有連接的情況下不會失敗

當兩個在模擬器和設備(通過關閉的Wi-Fi)中測試這種情況下,代替的接收呼叫到request:didFailWithError:,我接收呼叫productsRequest:didReceiveResponse:一個空的產品陣列,然後requestDidFinish:

這是預期的行爲?如果是這樣,我怎麼知道由於連接問題導致請求失敗?如果沒有,可能會出錯?

萬一有幫助,這是我要求的產品:

- (void) requestProducts:(NSSet*)identifiers 
{ 
    _productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers]; 
    _productsRequest.delegate = self; 
    [_productsRequest start]; 
} 

我使用的是iOS 6

回答

1

我不知道,如果它的預期的行爲,因爲該文檔是一個小對主題稀少。但我總是自己做檢查,這樣我就可以向用戶提供很好的錯誤消息,因爲看起來StoreKit錯誤的一半時間是非常不倫不類的。這是我在最近的一個項目中使用的一些代碼。

我有我自己的storeManager委託來簡化調用和繼承,但它應該很清楚發生了什麼。

#pragma mark - Purchase Methods 

- (void)purchaseProduct:(SKProduct *)product 
{ 
    // Check Internet 
    if ([self checkInternetConnectionAndAlertUser:YES]) { 

     // Check Restrictions 
     if ([self checkRestrictionsAndAlertUser:YES]) { 

      // Check Products 
      if ([_products containsObject:product]) { 

       // Purchase the product 
       [[SKPaymentQueue defaultQueue] addPayment:[SKPayment paymentWithProduct:product]]; 

      } else { 
       [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Sorry, we couldn't find that product." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 
       [self.delegate purchaseDidFailWithError:[NSError errorWithDomain:@"SDInAppPurchaseManager" code:404 userInfo:@{ NSLocalizedDescriptionKey : @"Product not found." }]]; 
      } 
     } else { 
      // Not allowed to make purchase 
      [self.delegate requestdidFailWithError:[NSError errorWithDomain:@"SDInAppPurchaseManager" code:500 userInfo:@{ NSLocalizedDescriptionKey : @"Not authorized to make purchases." }]]; 
     } 
    } else { 
     // No Internet 
     [self.delegate requestdidFailWithError:[NSError errorWithDomain:@"SDInAppPurchaseManager" code:300 userInfo:@{ NSLocalizedDescriptionKey : @"No internet connection." }]]; 
    } 
} 
#pragma mark - Checks 

- (BOOL)checkInternetConnectionAndAlertUser:(BOOL)alert 
{ 
    if ([[SDDataManager dataManager] internetConnection]) { 
     return YES; 
    } else { 
     // Alert the user if necessary. 
     if (alert) { 
      [[[UIAlertView alloc] initWithTitle:@"No Connection" message:@"You don't appear to be connected to the internet. Please check your connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 
     } 

     return NO; 
    } 
} 

- (BOOL)checkRestrictionsAndAlertUser:(BOOL)alert 
{ 
    if ([SKPaymentQueue canMakePayments]) { 
     return YES; 
    } else { 
     // Alert the user if necessary. 
     if (alert) { 
      [[[UIAlertView alloc] initWithTitle:@"Purchases Disabled" message:@"In App Purchasing is disabled for your device or account. Please check your settings and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 
     } 

     return NO; 
    } 
} 
相關問題