2012-08-11 139 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];