IOS How to using UILocalNotification

1) When the app is closed, schedule a local notification that will fire in 24 hours
UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24];
    notification.alertBody = @"24 hours passed since last visit :(";
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
2)If the app is opened (before the local notification fires), 
    cancel the local notification
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}
3)Receiving the Notification
 - (void)application:(UIApplication *)app didReceiveLocalNotification:
                                                  (UILocalNotification *)notif {
 // Handle the notification when the app is running
 NSLog(@"Recieved Notification %@",notif);
}

Comments

Popular posts from this blog

LINUX Move and copy files using SSH

PHP Predefined Variables

Java : Variables Declaring