我正在从 C++ 实例创建一个 Objective C 类的实例。问题是当试图获取一些变量的值(在 obj c 实例中)时,我总是得到 0。一些 NSLogs 也被忽略了!:
目标 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(); 无效检查购买();InAppPurchaseManager * theStore; }
测试应用程序.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";
}
结果总是完成?0,即使我在购买时将其设置为 1 。还有NSLog(@"STORE: HELLO THERE"); 被忽略
我不明白发生了什么事