1

C++ インスタンスから Objective C クラスのインスタンスを作成しています。問題は、いくつかの変数 (obj c インスタンス内) の値を取得しようとすると、常に 0 になることです。一部の NSLog も無視されます!:

Objective C クラス: 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 クラス 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";
}

結果は常にFinishedですか?0購入時に 1 に設定しても. また、NSLog(@"STORE: HELLO THERE"); 無視されます

何が起こっているのかわかりません

4

1 に答える 1

1

ではgoToStoreFromMenu、 という名前の新しいローカル変数を宣言しますtheStore。では、同じ名前の他の変数をcheckPurchase参照しています。関数は、関数の最後でスコープ外になるローカル変数を初期化します。で最終的に参照する同じ変数を初期化する必要があります。goToStoreFromMenucheckPurchase

于 2011-03-13T20:22:13.833 に答える