2012-08-11 187 views
3

我正在使用最新的MKStoreKit進行應用內購買。我遇到的問題是,當應用程序啓動時沒有互聯網時,產品不會從應用商店加載。如果我再運行MKStoreKit沒有互聯網連接

- (void) buyFeature:(NSString*) featureId 
     onComplete:(void (^)(NSString* purchasedFeature, NSData*purchasedReceipt)) completionBlock   
     onCancelled:(void (^)(void)) cancelBlock; 

然後,它從來沒有運行任何的onComplete或onCancelled因爲它返回這裏時,沒有找到購買對象。

NSArray *allIds = [self.purchasableObjects valueForKey:@"productIdentifier"]; 
int index = [allIds indexOfObject:productId]; 

if(index == NSNotFound) return; <-- IT RETURNS HERE 

SKProduct *thisProduct = [self.purchasableObjects objectAtIndex:index]; 
    SKPayment *payment = [SKPayment paymentWithProduct:thisProduct]; 
    [[SKPaymentQueue defaultQueue] addPayment:payment]; 

它甚至不發回錯誤,所以用戶不會收到任何消息。

我想這應該是一個常見問題?我如何以最佳方式處理它?

回答

4

我解決它通過評估...

MKStoreKit.sharedManager.pricesDictionary.count == 0 

...知道我是否應該告訴應用程序商店是無法購買的用戶。然後我嘗試用這種方法來重新加載產品數據...

https://github.com/MugunthKumar/MKStoreKit/issues/75

...每次用戶有意購買和App Store根據上述不可用。

要更新時,在界面的產品被下載並準備購買,我聽了這個通知...

[NotificationCenter addObserver:self 
         selector:@selector(productsFetched:) 
          name:kProductFetchedNotification 
         object:nil];