Skip to content

Instantly share code, notes, and snippets.

@seaders
Last active October 14, 2015 01:43
Show Gist options
  • Save seaders/d3c9239d682e6223a6ba to your computer and use it in GitHub Desktop.
Save seaders/d3c9239d682e6223a6ba to your computer and use it in GitHub Desktop.
void LocalNotification(NSString* body, int seconds, NSString* action)
{
UILocalNotification *localNotification = [ [UILocalNotification alloc] init ];
if(localNotification == nil)
{
return;
}
// Set the fire date/time
[ localNotification setFireDate: [ [NSDate date] dateByAddingTimeInterval: seconds ] ];
[ localNotification setTimeZone: [NSTimeZone defaultTimeZone] ];
localNotification.applicationIconBadgeNumber = 1;
[ localNotification setHasAction: ![action isEqual:@""] ];
if( [localNotification hasAction] )
{
[localNotification setAlertAction: action];
}
[localNotification setAlertBody: body];
localNotification.soundName=UILocalNotificationDefaultSoundName;
[localNotification setHasAction: NO];
UIApplication *app = [UIApplication sharedApplication];
[app scheduleLocalNotification: localNotification];
NSLog(@"LocalNotification in %@ (%@)\nfor %@", localNotification.fireDate, localNotification.timeZone, localNotification.alertBody);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment