Local Push Notifications

Discussion in 'iOS Programming' started by GhostDZ9, May 17, 2011.

  1. macrumors regular

    Joined:
    Sep 13, 2010
    #1
    Hi Guys,

    I have read the documentation on developer.apple.com about the push notifications however I still can seem to get it right, is there someone I can talk to who can guide me on how to build local push notifications for my app?

    Regards,

    Ghost
     
  2. macrumors member

    Joined:
    Feb 1, 2007
    Location:
    Seattle, WA
    #2
    Local *push* notifications? You mean local notifications? Sure, here ya go:

    Code:
    UILocalNotification* note = [[UILocalNotification alloc] init];
    note.fireDate = [NSDate date];
    note.timeZone = [NSTimeZone defaultTimeZone];
    note.repeatInterval = NSDayCalendarUnit;
    note.alertBody = NSLocalizedString(@"It's a notification!",@"");
    note.alertAction = NSLocalizedString(@"Hi there",@"");
    [[UIApplication sharedApplication] scheduleLocalNotification:note];
    [note release];
    
     
  3. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    appdelegate =

    Code:
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
        NSLog(@"This was fired off");
    }
    
    viewDidload

    Code:
    UIApplication *app                = [UIApplication sharedApplication];
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        NSArray *oldNotifications         = [app scheduledLocalNotifications];
        
        if ([oldNotifications count] > 0) {
            [app cancelAllLocalNotifications];
        }
        
        if (notification == nil)
            return;
        
        NSDate *notificationDate = [NSDate dateWithTimeIntervalSinceNow:10];
        
        notification.fireDate  = notificationDate;
        notification.timeZone  = [NSTimeZone systemTimeZone];
        notification.alertBody = @"Woop example";
        
        [app scheduleLocalNotification:notification];
        
        [notification release];
    
    If the viewDidload is called, minus ur app, and wait 10 secs ;) gl :)
     
  4. thread starter macrumors regular

    Joined:
    Sep 13, 2010
    #4
    Great thanks guys, Ill try these out now, do you guys know if alerts work outside the app when it isn't launched?
     
  5. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    Afaik, u need the push notifications from Apple then, which is something totally different.. Sorry, no experience with that.
     
  6. thread starter macrumors regular

    Joined:
    Sep 13, 2010
    #6
    Well I want to have it so when the user sets a time for when they have to be back it shows a notification with the notes that they have entered in, how can i customize the code that you have given me?
     

Share This Page