no response when call buyFeature:(NSString*) featureId onComplete first time #80

Closed
macinux opened this Issue Aug 8, 2012 · 6 comments

Projects

None yet

6 participants

@macinux

Thanks for this framework that i can start with. I might not know exactly how to use this framework. Basically, there is nothing happens (no alert window popping up) when i call - (void) buyFeature:onComplete:(void (^) onCancelled:(void (^) first time.
I got "Confirm Your in-app purchase alert" when i call the buyFeature for the second time.

I also looked at the log, the first time it calls buyFeature:onComplete, method: productsRequest:didReceiveResponse: was called and it printed out NSLog(@"Feature: %@, Cost: %f, ID: %@",[product localizedTitle], and then it sends kProductFetchedNotification to the notificationCenter. But no code is actually handling this notification. Did I do something wrong?

Thanks in advance,
James

@MajorApps

We are also seeing this issue, please can someone verify.

@codegefluester

I had the same issue and the solution is pretty simple. MKStoreKit first has to load all available products from iTunes Connect, this request may take some time to finish. And that's why it does not work the first time but the second time.
MKStoreKit posts a notification when the product list is loaded, so just disable any UI components that initiate a purchase, add an observer for the notification and then re-enable the UI components when the request is complete and the list is loaded.

A quick example of how I'm doing it:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productsLoaded:) name:kProductFetchedNotification object:nil];
    self.manager = [MKStoreManager sharedManager];

    self.adSwitch = [[UISwitch alloc] init];
    [self.adSwitch setOn:NO];
    [self.adSwitch addTarget:self action:@selector(adSwitchDidChange:) forControlEvents:UIControlEventValueChanged];
    self.adSwitch.enabled = NO;
}

- (void) productsLoaded:(NSNotification*)notification
{
    self.adSwitch.enabled = YES;
    [self.adSwitch setOn:[MKStoreManager isFeaturePurchased:@"XXXXX"]];
}

Hope this helps.

Cheers,
Björn

@stoni23

for us nubs how do you declare manager in the header file

@MugunthKumar

You should always initialize MKStoreKit in the App Delegate and check if isProductsLoaded method before calling purchase.

@stoni23

I do initialize in the app delegate, but how do you check if isProductsLoaded method, just copying and pasting that gives a bunch of errors because manager is undeclared, where do you declare it.

@ShockUtility

Simple code

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productsLoaded:) name:kProductFetchedNotification object:nil];
    [MKStoreManager sharedManager];
    }

  • (void) productsLoaded:(NSNotification*)notification
    {
    [MKStoreManager isFeaturePurchased:@"xxx"];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment