3

我有一个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
4

2 回答 2

2

您可能没有productPurchasedproductPurchased. 还要确保注册通知的 viewController 实现了这个方法。如果方法是在另一个类中定义的,则更改该行以适合您的 className 而不是 self。

 [[NSNotificationCenter defaultCenter] addObserver:yourClassObject selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil];

viewDidLoad方法中添加观察者而不是viewWillAppear

于 2013-04-19T14:26:56.823 回答
2

我认为您没有productPurchasedAlarmSelectViewController.

注意:您可以在某处实施。找到并纠正它。

于 2013-04-19T14:28:09.610 回答