【发布时间】:2014-06-07 08:43:27
【问题描述】:
我正在尝试将应用内购买集成到我使用 cocos2d x c++ 制作的应用中。我正在使用 easyNdk Helper 进行应用内购买。我的应用内购买非常适合我的 Objective C 应用。但是对于 cocos2d x 它会抛出以下行的错误
if ([[RageIAPHelper sharedInstance] productPurchased:productP.productIdentifier])
实际上值以参数的形式完美地来自 CPP 文件,并在 NSLog 中正确显示它们的值,但它总是将对象显示为 nil,甚至 objetcs 在 NSLog 中打印它们的存储值
@try catch 条件也不起作用
最后抛出如下错误
请帮我做什么? 谢谢
我的 .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文件的这个值,是char*吗?另外,您是否在 MM 文件中记录了此值?另外,您正在使用的这个对象的 retaincount 是多少?
-
@Al-mo 嗨亲爱的,我将参数作为 CCDictionary 从 .cpp 文件传递到 .mm 文件,然后将其转换为 NSDictionary 我没有在我的项目中使用任何保留关键字,因为它是弧项目。恐怕我现在不必在哪里设置retaincount :(,我不知道“您是否在MM文件中记录了这个值”是什么意思我还尝试使用CCUserDefault设置该值,然后尝试通过 NSUserDefault 获取技术,但存在同样的问题 :(
-
在发送之前,您能否检查一下您的字典的 RETAINCOUNT 是多少,并且,当您收到这本字典时,您是接受它作为 NSDICTIONARY(参数)还是创建一个 NSDictionary对象使用您从 CPP 文件发送的字典?
-
另外,请确保您在传递之前保留了这本词典。当您尝试访问它时,它可能会自动释放。我需要查看代码才能更好地理解。
-
@Al-mo 我已将代码包含在我的问题中,您可以检查一下
标签: c++ ios objective-c in-app-purchase cocos2d-x