我正在嘗試使用cocos2d x C++在應用程序中集成應用程序購買。我正在使用easyNdk助手進行應用內購買。我的應用程序購買完美適用於我的Objective C應用程序。但對於cocos2d的X是以下行Cocos2dx InApp爲ios購買
if ([[RageIAPHelper sharedInstance] productPurchased:productP.productIdentifier])
其實值從CPP進來的參數形式完美的文件,並正確顯示其在NSLog的值拋出錯誤,但它總是顯示對象作爲零甚至objetcs打印其在NSLog的
儲值還@try捕捉條件不工作
終於拋出了以下錯誤
請幫助我,我有什麼關係? 感謝
我.CPP代碼
NDKHelper::AddSelector("HelloWorldSelectors",
"SampleSelector",
callfuncND_selector(Main::cameFromObjC),
this);
CCDictionary* prms = CCDictionary::create();
prms->setObject(CCString::create("SampleSelector"), "to_be_called");
prms->setObject(CCString::create(result), "BirdNameKey");
SendMessageWithParams(string("SampleSelector"), prms);
和.mm代碼
- (void) SampleSelector:(NSObject *)prms
{
NSLog(@"purchase something called");
NSDictionary *parameters = [[NSDictionary alloc]init];// (NSDictionary*)prms;
parameters = (NSDictionary*)prms;
NSLog(@"Passed params are : %@", parameters);
// Fetching the name of the method to be called from Native to C++
// For a ease of use, i have passed the name of method from C++
NSString* CPPFunctionToBeCalled = (NSString*)[parameters objectForKey:@"to_be_called"];
//NSString *str = [NSString stringWithFormat:@"%@",[parameters valueForKey:@"BirdNameKey"]];
NSString *BirdName = [parameters valueForKey:@"BirdNameKey"];
NSString *str = [[NSString alloc]initWithFormat:@"%@",[parameters objectForKey:@"BirdNameKey"]];
NSUserDefaults *d2 = [NSUserDefaults standardUserDefaults];
NSLog(@"%@ , %@ , %@", str,BirdName,[d2 objectForKey:@"product"]); // output is ok for all
SKProduct * product = (SKProduct *) [ APPDELEGATE.productDictionary objectForKey:[d2 objectForKey:@"product"]];
[ APPDELEGATE.priceFormatter setLocale:product.priceLocale];
APPDELEGATE.currentProduct =product;
if ([[RageIAPHelper sharedInstance] productPurchased:product.productIdentifier])
{
// check the product purchased or not but app crash at this if statement
}
[IOSNDKHelper SendMessage:CPPFunctionToBeCalled WithParameters:nil];
}
你發送給這個MM文件這個值,是字符*?另外,你有沒有在MM文件中記錄這個值?另外,您使用的這個對象的剩餘部分是什麼? –
@ Al-mo嗨,親愛的,我將參數從.cpp文件傳遞給.mm文件,然後將其轉換爲NSDictionary。我的項目中沒有使用任何retain關鍵字,因爲它是ARC項目。恐怕我現在不應該在那裏我必須設置retaincount :(,我不知道你是什麼意思的「你有沒有在MM文件中記錄這個值」我也嘗試使用CCUserDefault設置值,然後試圖通過NSUserDefault來解決問題,但同樣的問題存在:( –
在發送之前,你能檢查什麼是你的字典的RETAINCOUNT,並且當你收到這本字典時,你接受它作爲NSDICTIONARY(參數)還是你使用從CPP文件發送的Dictory創建了一個NSDictionary對象? –