我正在尝试使用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对象? –