1

I am creating an instance of an Objective C class from a C++ instance. The problem is that when trying to get the values of some vars (in the obj c instance) I always get 0. Some NSLogs are also ignored!:

Objective C class: InAppPurchaseManager.h

@interface InAppPurchaseManager : NSObject <SKProductsRequestDelegate, SKPaymentTransactionObserver>{
    SKProduct *proUpgradeProduct;
    SKProductsRequest *productsRequest;
@public
    int finishedPurchaseProcess;
}
- (int)hasFinishedPurchaseProcess;
- (void)purchase;
@end

InAppPurchaseManager.m

@implementation InAppPurchaseManager
- (void)purchase{
    finishedPurchaseProcess=1;
}
- (int)hasFinishedPurchaseProcess{
    NSLog(@"STORE: HELLO THERE");   
    return finishedPurchaseProcess;
}

testApp.h class testApp : public ofxiPhoneApp { public: void goToStoreFromMenu(); void checkPurchase(); InAppPurchaseManager * theStore; }

testApp.mm

// First I call ghis function
void testApp::goToStoreFromMenu(){  
    InAppPurchaseManager* theStore = [[InAppPurchaseManager alloc] init];
    [theStore purchase];
}

// And then this function
void testApp::checkPurchase(){  
    cout << "Finished? " << [theStore hasFinishedPurchaseProcess] << "\n";
}

and the result is always Finished? 0, even if I set it to 1 in purchase. Also the NSLog(@"STORE: HELLO THERE"); is ignored

I don't understand what's going on

2
  • did you try debug your app? does it reach NSLog(...) when debugged ? Commented Mar 13, 2011 at 20:15
  • Have you tried removing the InAppPurchaseManager* in testApp::goToStoreFromMenu? Commented Mar 13, 2011 at 20:22

1 Answer 1

1

In goToStoreFromMenu, you declare a new local variable named theStore. In checkPurchase, you refer to some other variable with the same name. The goToStoreFromMenu function initializes the local variable, which goes out of scope at the end of the function. You need to initialize the same variable that you'll eventually refer to in checkPurchase.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, I forgot to include testApp.h, where theStore is declared. I edited the question accordingly. Thanks
You still appear to be declaring an additional, separate variable called 'theStore', in testApp::goToStoreFromMenu.
oh! Now I understand! You are right, it should be theStore = [[InAppPurchaseManager alloc] init]; . Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.