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

GhostDZ9

macrumors regular
Original poster
Sep 13, 2010
118
0
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
 
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

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];
 
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 :)
 
Great thanks guys, Ill try these out now, do you guys know if alerts work outside the app when it isn't launched?
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.