Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

onedirection32

macrumors newbie
Original poster
Sep 3, 2013
4
0
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:

Code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Adding activity indicator
activityIndicatorView = [[UIActivityIndicatorView alloc]
                                initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
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.
}

-(void)fetchAvailableProducts{
NSSet *productIdentifiers = [NSSet
                             setWithObjects:@“IAP_ID",nil];
productsRequest = [[SKProductsRequest alloc]
                   initWithProductIdentifiers:productIdentifiers];
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];
}
else{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                              @"Purchases are disabled in your device"     message:nil delegate:
                              self cancelButtonTitle:@"Ok" otherButtonTitles:     nil];
    [alertView show];
}
}
-(IBAction)purchase:(id)sender{
[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:
            NSLog(@"Purchasing");
            break;
        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];
            break;
        case SKPaymentTransactionStateRestored:
            NSLog(@"Restored ");
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
            NSLog(@"Purchase failed ");
            break;
        default:
            break;
    }
}
}

-(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"
                        delegate:self
                        cancelButtonTitle:nil
                        otherButtonTitles:@"Ok", nil];
    [tmp show];
}    
[activityIndicatorView stopAnimating];
purchaseButton.hidden = NO;
}

@end

Here is the error message:

Code:
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

(lldb)

Any help would be greatly appreciated.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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?
 

Ubuntu

macrumors 68020
Jul 3, 2005
2,157
490
UK/US
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).
 

onedirection32

macrumors newbie
Original poster
Sep 3, 2013
4
0
Method exception

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

Attachments

  • Screen Shot 2015-03-14 at 5.21.13 PM.png
    Screen Shot 2015-03-14 at 5.21.13 PM.png
    119.5 KB · Views: 119

onedirection32

macrumors newbie
Original poster
Sep 3, 2013
4
0
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.
 

impossiballs

macrumors newbie
Apr 8, 2015
12
0
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.

Just a guess: if Purchase is a UIViewController perhaps you meant to access the superview of the view property of that controller?
 

onedirection32

macrumors newbie
Original poster
Sep 3, 2013
4
0
I have searched my entire project, but could not find a “superview” command anywhere.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.