AlertViews not showing up?

Discussion in 'iOS Programming' started by ArtOfWarfare, Dec 13, 2011.

  1. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #1
    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?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Hmm, perhaps that's part of the problem. What is happening in requestAds? Could it somehow be preventing the code below it from actually working? When you used the breakpoint, did you try stepping through the code?
     
  3. ArtOfWarfare thread starter macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    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?
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium

Share This Page