gpt4 book ai didi

c++ - Cocos2dx InApp Purchase for ios

转载 作者:行者123 更新时间:2023-11-28 06:50:12 24 4
gpt4 key购买 nike

我正在尝试将 In App Purchases 集成到我使用 cocos2d x c++ 制作的应用程序中。我正在使用 easyNdk Helper 进行应用内购买。我的应用内购买非常适合我的 Objective C 应用。但是对于 cocos2d x 它会为以下行抛出错误

if ([[RageIAPHelper sharedInstance] productPurchased:productP.productIdentifier])

实际上,值以参数的形式完美地来自 CPP 文件,并在 NSLog 中正确显示它们的值,但它始终将对象显示为 nil,甚至对象在 NSLog 中打印它们的存储值

@try catch 条件也不起作用

最后抛出如下错误enter image description here

请帮助我我必须做什么?谢谢

我的.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];
}

最佳答案

我也遇到过这个问题,我已经解决了。在你的 IAPhelper.mm 中

只做这个替换这一行

_purchasedProductIdentifiers = [NSMutableSet set];

下面一行

_purchasedProductIdentifiers = [[NSMutableSet alloc] init];

如下图

 - (id)initWithProductIdentifiers:(NSSet *)productIdentifiers {

if ((self = [super init])) {

// Store product identifiers
_productIdentifiers = productIdentifiers;

// Check for previously purchased products
// _purchasedProductIdentifiers = [NSMutableSet set];
_purchasedProductIdentifiers = [[NSMutableSet alloc] init];
for (NSString * productIdentifier in _productIdentifiers) {
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
if (productPurchased) {
[_purchasedProductIdentifiers addObject:productIdentifier];
// NSLog(@"Previously purchased: %@", productIdentifier);
} else {
// NSLog(@"Not purchased: %@", productIdentifier);
}
}

// Add self as transaction observer
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

}
return self;

}

关于c++ - Cocos2dx InApp Purchase for ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24095454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com