Updating price of in app purchase

2019-06-01 06:05发布

问题:

I have a custom alert view that pops up in my app asking the user if they'd like to purchase one of my in app purchases. In the alert view, I also list the price of the in app purchase which I derive from the SKProduct associated with it.

The thing is, now I want to change the price of my in app purchase, but I'm collecting the product data when the app launches in the app delegate, so how should I go about this? (does the app delegate only launch when the first time the user launches the app?).

Each time I display the dialogue, do I need to query Apple to reload the products data? That sounds really inefficient...

By chance, if you update the price of one of your in app purchases, will the SKProductsRequestDelegate be alerted so it will update your products automatically?

Does anyone have a good solution to this situation?

回答1:

Seems the best way to remedy this situation is to load the products when the app launches and reload the products every time the app becomes active. Implementing the following method in the app delegate takes care of the problem:

- (void) applicationWillEnterForeground:(UIApplication *)application
{
    [self loadProducts];
}

- (void) loadProducts
{
    self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObjects: MyProduct1, MyProduct2 nil]];
    self.productsRequest.delegate = self;
    [self.productsRequest start];
}