PDA

View Full Version : Local Push Notifications




GhostDZ9
May 17, 2011, 08:33 PM
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



aaronbrethorst
May 17, 2011, 10:08 PM
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:


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];

jnoxx
May 18, 2011, 03:06 AM
appdelegate =


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


viewDidload

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

GhostDZ9
May 18, 2011, 08:10 AM
Great thanks guys, Ill try these out now, do you guys know if alerts work outside the app when it isn't launched?

jnoxx
May 18, 2011, 08:13 AM
Afaik, u need the push notifications from Apple then, which is something totally different.. Sorry, no experience with that.

GhostDZ9
May 18, 2011, 08:16 AM
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?