我有一个UITableView
用户可以从中选择自定义声音。我有 3 个 IAP 非消耗品,我根据index.section
用户从中选择的逻辑内置了逻辑。逻辑上的UIToolbarButton
更改(用户可以单独IBAction
保存选择,但前提是他们“购买”了产品):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Pull identifiers for IAP
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
bool alarmpackpurchased = [defaults boolForKey:@"Alarm_Pack"];
bool annoyancepackpurchased = [defaults boolForKey:@"Annoyance_Pack"];
bool serenepackpurchased = [defaults boolForKey:@"Serene_Pack"];
// Defualt index will always be allowed to save
if(indexPath.section == 0) {
savebuybutton.enabled = YES;
savebuybutton.title = @"Save";
savebuybutton.tintColor = [UIColor blueColor];
}
else {
if (indexPath.section == 1 && alarmpackpurchased == TRUE) {
savebuybutton.enabled = YES;
savebuybutton.title = @"Save";
savebuybutton.tintColor = [UIColor blueColor];
}
else if (indexPath.section == 2 && annoyancepackpurchased == TRUE) {
savebuybutton.enabled = YES;
savebuybutton.title = @"Save";
savebuybutton.tintColor = [UIColor blueColor];
}
else if (indexPath.section == 3 && serenepackpurchased == TRUE) {
savebuybutton.enabled = YES;
savebuybutton.title = @"Save";
savebuybutton.tintColor = [UIColor blueColor];
}
else {
savebuybutton.enabled = YES;
savebuybutton.title = @"Buy Pack";
savebuybutton.tintColor = [UIColor redColor];
}
}
}
这是viewWillAppear:
通知观察者的方法:
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil];
}
这是我在完成此产品的 IAP 后收到的错误:
2013-04-19 10:08:12.086 SleepLabBeta[43395:c07] -[AlarmSelectViewController productPurchased:]: unrecognized selector sent to instance 0x11444940
2013-04-19 10:08:12.125 SleepLabBeta[43395:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AlarmSelectViewController productPurchased:]: unrecognized selector sent to instance 0x11444940'
*** First throw call stack:
(0x1bf5012 0x1666e7e 0x1c804bd 0x1be4bbc 0x1be494e 0x11274f9 0x1c4f0c5 0x1ba9efa 0x105bbb2 0x1f57a 0x1f0b3 0x1eeae 0x924b1 0x1b978fd 0x92437 0x930fa 0x93d27 0x922a4 0x227653f 0x2288014 0x22787d5 0x1b9baf5 0x1b9af44 0x1b9ae1b 0x1a3e7e3 0x1a3e668 0x5aaffc 0x297d 0x28a5)
libc++abi.dylib: terminate called throwing an exception