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

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,706
6,289
AlertViews and NSLogs are being displayed when one class tells them to but not another?

Here's a method from my app delegate:
Code:
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if (url != nil && [url isFileURL])
    {
        if ([[NSDate date] timeIntervalSince1970] < 1328054400)
        {
            //The promotion hasn't expired yet! Read the file!
            NSData *promotionalData = [NSData dataWithContentsOfURL:url];
            NSString *promotionalString = [[NSString alloc] initWithData:promotionalData encoding:NSUTF8StringEncoding];
            NSLog(@"%@", promotionalString);
            if ([promotionalString isEqualToString:@"This Quick Clips Promo Code is good until December 14th, 2011."])
            {
                NSLog(@"The files match and it's not too late! Hurray!");
                [self.viewController successfulPurchase];
                
                [[NSUserDefaults standardUserDefaults] setObject:promotionalData forKey:@"promo"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Promotional Code Activated!" message:@"You may use the premium version of Quick Clips for free until January 31st, 2011. Enjoy!" delegate:nil cancelButtonTitle:@"Thanks!" otherButtonTitles:nil];
                [alertView show];
                [alertView release];
            }
            else
            {
                NSLog(@"The files don't match. Boo!");
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Invalid Promotional Code!" message:@"Sorry, this promotional code isn't valid." delegate:nil cancelButtonTitle:@"Boo!" otherButtonTitles:nil];
                [alertView show];
                [alertView release];
            }
        }
        else
        {
            NSLog(@"The promotion has ended. Boo!");
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Promotional Period is Over!" message:@"Sorry, this promotion has ended." delegate:nil cancelButtonTitle:@"Boo!" otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }
    }
    
    else
    {
        NSLog(@"Nothing to open and read!");
    }
    return YES;
}

Again, these messages show up fine. The NSLogs show up at the right times, and the UIAlertViews show up at the right times.

In a second class,
Code:
- (void)verifyReceipt:(NSData *)receipt promo:(BOOL)promo
{
        if ([[NSDate date] timeIntervalSince1970] < 60)
        {
            NSString *promotionalString = [[NSString alloc] initWithData:receipt encoding:NSUTF8StringEncoding];
            NSLog(@"%@", promotionalString);
            if ([promotionalString isEqualToString:@"This Quick Clips Promo Code is good until December 14th, 2011."])
            {
                NSLog(@"The files match and it's not too late! Hurray!");
            }
            else
            {
                NSLog(@"The files don't match. Boo!");
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"promo"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                [self requestAds];
                
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Invalid Promotional Code!" message:@"Sorry, this promotional code isn't valid. Please upgrade via the help menu to continue using premium features." delegate:self cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Upgrade", nil];
                [alertView show];
                [alertView release];
            }
            [promotionalString release];
        }
        else
        {
            NSLog(@"The promotion has ended. Boo!");
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"promo"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            [self requestAds];
            
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Promotional Period is Over!" message:@"Sorry, the premium promotion is over. Please upgrade via the help menu to continue using premium features." delegate:self cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Upgrade", nil];
            [alertView show];
            [alertView release];
        }
    }

Ads end up getting shown, which is right, but no NSLog messages are put out, and UIAlertViews aren't displayed... I've also set break points and found that those are tripped, so this method is getting used.

Any suggestions for why this isn't working?
 
If I place a breakpoint at
if (promo), it'll move onto
if (date > ....), then...

stepping through it worked just now?

What the heck?

I just tested it several times and without any modifications it worked every time.

The only things I can think of that I've done since last night when I posted this just before going to sleep were:

- Disconnected and reconnected my iPhone from my computer.
- Quit and opened Xcode.

I guess maybe Xcode had somehow messed up after running all day yesterday?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.