Xcode 6.1.1 iOS simulator error: -[Purchase superview]: unrecognized selector sent to

Discussion in 'iOS Programming' started by onedirection32, Mar 12, 2015.

  1. onedirection32 macrumors newbie

    Sep 3, 2013
    I am developing an iOS app using Xcode 6.1.1. When I press a button on my main ViewController, “ViewController”, it is supposed to modal segue to a second, “Purchase”. However, the app crashes on the iOS simulator. I have tried cleaning my project, restarting Xcode, and deleting non-existent connections in the .storyboard. However, nothing seems to work. Also, "All Exceptions" in the breakpoints are turned on. Here is the code for Purchase.m:

    - (void)viewDidLoad
    [super viewDidLoad];
    // Adding activity indicator
    activityIndicatorView = [[UIActivityIndicatorView alloc]
    activityIndicatorView.center = self.view.center;
    [activityIndicatorView hidesWhenStopped];
    [self.view addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    //Hide purchase button initially
    purchaseButton.hidden = YES;
    [self fetchAvailableProducts];
    - (void)didReceiveMemoryWarning
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSSet *productIdentifiers = [NSSet
    productsRequest = [[SKProductsRequest alloc]
    productsRequest.delegate = self;
    [productsRequest start];
    - (BOOL)canMakePurchases
    return [SKPaymentQueue canMakePayments];
    - (void)purchaseMyProduct:(SKProduct*)product{
    if ([self canMakePurchases]) {
        SKPayment *payment = [SKPayment paymentWithProduct:product];
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                  @"Purchases are disabled in your device"     message:nil delegate:
                                  self cancelButtonTitle:@"Ok" otherButtonTitles:     nil];
        [alertView show];
    [self purchaseMyProduct:[validProducts objectAtIndex:0]];
    purchaseButton.enabled = NO;
    #pragma mark StoreKit Delegate
    -(void)paymentQueue:(SKPaymentQueue *)queue
    updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
            case SKPaymentTransactionStatePurchased:
                if ([transaction.payment.productIdentifier
                     isEqualToString:@"9plus10equals21"]) {
                    NSLog(@"Purchased ");
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                              @"Purchase is completed succesfully"     message:nil delegate:
                                              self cancelButtonTitle:@"Ok"     otherButtonTitles: nil];
                    [alertView show];
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            case SKPaymentTransactionStateRestored:
                NSLog(@"Restored ");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            case SKPaymentTransactionStateFailed:
                NSLog(@"Purchase failed ");
    -(void)productsRequest:(SKProductsRequest *)request
    didReceiveResponse:(SKProductsResponse *)response
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if (count>0) {
        validProducts = response.products;
        validProduct = [response.products objectAtIndex:0];
        if ([validProduct.productIdentifier
             isEqualToString:@“IAP_ID"]) {
            [productTitleLabel setText:[NSString stringWithFormat:
                                        @"Product Title:     %@",validProduct.localizedTitle]];
            [productDescriptionLabel setText:[NSString stringWithFormat:
                                              @"Product Desc:     %@",validProduct.localizedDescription]];
            [productPriceLabel setText:[NSString stringWithFormat:
                                        @"Product Price: %@",validProduct.price]];
    } else {
        UIAlertView *tmp = [[UIAlertView alloc]
                            initWithTitle:@"Not Available"
                            message:@"No products to purchase"
                            otherButtonTitles:@"Ok", nil];
        [tmp show];
    [activityIndicatorView stopAnimating];
    purchaseButton.hidden = NO;
    Here is the error message:

    2015-03-12 21:07:17.537 Phone hack prank [7951:190128] [RevMob] Starting RevMobAds
    2015-03-12 21:07:18.673 Phone hack prank [7951:190128] Session started with block
    2015-03-12 21:07:18.674 Phone hack prank [7951:190128] [RevMob] Initializating Banner.
    2015-03-12 21:07:18.674 Phone hack prank [7951:190128] [RevMob] Requesting banner data.
    2015-03-12 21:07:19.067 Phone hack prank [7951:190128] [RevMob] App successfully registered in RevMob servers
    2015-03-12 21:07:19.761 Phone hack prank [7951:190128] [RevMob] Ad received: (200) - 54d09c111f65897f4b95219e
    2015-03-12 21:07:20.338 Phone hack prank [7951:190128] [RevMob] Banner did received.
    2015-03-12 21:07:20.341 Phone hack prank [7951:190128] [RevMob] Banner displayed.
    2015-03-12 21:07:22.682 Phone hack prank [7951:190128] -[Purchase superview]: unrecognized selector sent to instance 0x7fbb627da970
    Any help would be greatly appreciated.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Is there any reference to a method named superview in your app? And to be clear 'Purchase' is the class name of a view controller in your app?

    Can you show the stack trace for the crash?

    Can you tell us which code in the view controller is executed immediately before the crash?

    Obviously, most of the NSLog output you show comes from the RevMob ad code. It's possible the bug is in that code or is due to your code not doing something correctly related to displaying the ads.\

    Does the Purchase view controller show ads?
  3. Ubuntu macrumors 68000


    Jul 3, 2005
    First of all, great idea to enable the All Exceptions breakpoint - I wish that was default behaviour. Now, when the app encounters the exception it should show the instruction pointer (the green line) at the point where the exception has been encountered. Can you provide a code snippet of the method where that exception occurs?

    Also, answering the points PhoneyDeveloper made would be a great help in order to help you. I should add that you might want to rename your class from Purchase to PurchaseViewController (for example). It's a lot clearer to other developers what the class is and can help with debugging (just off of the name I'd have assumed Purchase was a model object, not a ViewController).
  4. onedirection32 thread starter macrumors newbie

    Sep 3, 2013
    Method exception

    In response to Ubuntu, here is the code snippet (main.m):

    Attached Files:

  5. onedirection32 thread starter macrumors newbie

    Sep 3, 2013
    In response to PhoneyDeveloper, it is a View Controller. It also shows a banner ad. However, it is triggered in a previous view controller/class.
  6. impossiballs macrumors newbie


    Apr 8, 2015
    Just a guess: if Purchase is a UIViewController perhaps you meant to access the superview of the view property of that controller?
  7. onedirection32 thread starter macrumors newbie

    Sep 3, 2013
    I have searched my entire project, but could not find a “superview” command anywhere.

Share This Page

6 March 12, 2015