我的视图控制器上有一个按钮,用于显示我的应用内购买商店。
storeSinglePlayer *ssp = [[storeSinglePlayer alloc] initWithNibName:@"storeSinglePlayer" bundle:nil];
//Animation Code
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:ssp animated:NO];
导航控制器成功地将这个商店推送到屏幕上。商店有一个执行以下代码的后退按钮:
[self.request cancel];
self.request.delegate = nil;
self.request = nil;
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
这也成功执行。但是,如果我现在单击按钮再次显示商店视图控制器,我会收到以下消息:
-[storeSinglePlayer respondsToSelector:]: message sent to deallocated instance 0xd642df0
这确实是一个非常有名的问题。正如您将在上面的代码中注意到的那样,我已经合并了我在 stackoverflow 上遇到的各种帖子的建议。已实现以下代码:
[self.request cancel];
self.request.delegate = nil;
self.request = nil;
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
我也将我的属性和相应的合成设置为:
@property (nonatomic, strong) SKProductsRequest *request;
@synthesize request = _request;
我不知道,为什么会崩溃!
PS:该项目启用了ARC。