我是cocos2d的新手,所以我的应用内购买类助手出了问题。我在Cocoa Touch中编写游戏并且这个类完美地运行,但我现在在Cocos2d中编写相同的游戏,问题在于NSString。
以下是一些摘录。
当我点击某个按钮时,首先调用此方法。如您所见completeIdentifier
是带有bundleIdentifier
的简单字符串和一些字符串参数。没关系,在这个地方我可以记录这个completeIdentifier
。
- (void)prepareToPurchaseItemWithIdentifier:(NSString *)aIdentifier showAlertWithTitle:(NSString *)title description:(NSString *)description delegate:(id)aDelegate{
self.delegate = aDelegate;
identifier = aIdentifier;
completeIdentifier = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] bundleIdentifier], aIdentifier];
askToPurchase = [[UIAlertView alloc] initWithTitle:title message:description delegate:self cancelButtonTitle:nil otherButtonTitles:@"Later", @"Yes", nil];
askToPurchase.delegate = self;
[askToPurchase show];
}
下一个方法是UIAlertViewDelegate
方法。当我从第一种方法点击YES
上的alertView
时调用。
#pragma mark - UIAlertViewDelegate Methods
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"%@", completeIdentifier);
if (alertView == askToPurchase) {
NSLog(@"[TSIAPHelper] Clicked YES. Prepare...");
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"[TSIAPHelper] Prepare to purchase [%@].",completeIdentifier);
SKProductsRequest *request =[[SKProductsRequest alloc] initWithProductIdentifiers:
[NSSet setWithObject:completeIdentifier]];
request.delegate = self;
[request start];
pleaseWait = [[UIAlertView alloc] initWithTitle:@"Please wait..." message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[activity startAnimating];
[pleaseWait addSubview:activity];
activity.frame = CGRectMake(125, 50, 36, 36);
[pleaseWait show];
}
else {
NSLog(@"[TSIAPHelper] Purchase [FAILURE]. Prohibited by Parentar Control or something like that.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Prohibited." message:@"Parental Control is enabled, cannot make a purchase. Turn off and try again." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
}
}
}
问题是:无论何时何地,我想记录变量completeIdentifier
我已经崩溃了选定的行:0x39e965d0: ldr r3, [r4, #8]
但我不知道这是什么意思。选择此行:
NSLog(@"%@", completeIdentifier);
我该如何解决?在Cocoa Touch中运作完美。当我使用cocos2d时不是。
答案 0 :(得分:1)
我猜你还没有使用ARC。在这种情况下,completeIdentifier将被自动释放。
Cocos2d每帧清除自动释放池,而在Cocoa中,这并没有严格定义,但可能仍会崩溃。您可以通过保留或复制字符串来解决此问题。
completeIdentifier = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] bundleIdentifier], aIdentifier];
completeIdenfitier = [completeIdentifier retain];