Ios 无法识别的选择器发送到应用内购买产品的实例错误

Ios 无法识别的选择器发送到应用内购买产品的实例错误,ios,objective-c,in-app-purchase,Ios,Objective C,In App Purchase,我有一个UITableView,用户可以从中选择自定义声音。我有3个用于IAP的非消耗品,基于用户从中选择的index.section,我为其内置了逻辑。UIToolbarButton在逻辑上会发生变化。有一个单独的iAction,用户可以在其中保存选择,但前提是他们已经购买了产品: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Pull

我有一个UITableView,用户可以从中选择自定义声音。我有3个用于IAP的非消耗品,基于用户从中选择的index.section,我为其内置了逻辑。UIToolbarButton在逻辑上会发生变化。有一个单独的iAction,用户可以在其中保存选择,但前提是他们已经购买了产品:

- (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];
        }
    }
}
下面是带有通知观察者的viewwillappease:method:

- (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

您可能没有实现productPurchased,或者在productPurchased中使用了错误的参数。还要确保注册通知的viewController已实现此方法。如果方法是在另一个类中定义的,则更改行以适合您的类名,而不是self

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

在viewDidLoad方法中添加观察者,而不是ViewWillDisplay

我认为您没有在AlarmSelectViewController中实现productPurchased方法


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

我从另一个类导入了此方法:-BOOLproductPurchased:NSString*productIdentifier{return[\u purchasedProductIdentifiers containsObject:productIdentifier];}方法应该在添加观察者的类中。我刚刚尝试在viewDidLoad中添加观察者,结果相同。productPurchased位于IAPHelper.m中,我已将其设置为在此视图控制器上导入。在观察者中设置self有问题吗?是的,你应该用你的类名而不是self,以防在你的类中定义了方法谢谢你,仅供参考,你和另一个人的答案相同,但他以两分钟的优势击败了你,没有什么不快的感觉吗?以下是我添加的方法:-voidproductPurchased:NSNotification*notification{NSString*productIdentifier=notification.object;[\u products enumerateObjectsUsingBlock:^SKProduct*product,NSUInteger idx,BOOL*stop{if[product.productIdentifier IsequalString:productIdentifier]{//do somethine here*stop=YES;}}}}我已从另一个类导入此方法:-BOOLproductPurchased:NSString*productIdentifier{return[\u purchasedProductIdentifiers containsObject:productIdentifier];}但是您将addObserver:设置为self。?那么如何获取它将调用?如果该类是AlarmSelectViewController的超类,它将被激发。用您的代码检查..您是说不会用包含ProductPurchaseMethod.h的类检索和导入该观察者吗?当然。它不会激发..用您的代码检查..实现相同的情况n在另一段代码中检查此逻辑…谢谢!添加了以下内容:-voidproductPurchased:NSNotification*notification{NSString*productIdentifier=notification.object;[\u products enumerateObjectsUsingBlock:^SKProduct*product,NSUInteger idx,BOOL*stop{if[product.productIdentifier isEqualToString:productIdentifier]{//在此处执行操作*stop=YES;}}};}