localnotifiaction

//
//  AppDelegate.m
//  loclanotification
//
//  Created by MAC OS on 1/11/1938 Saka.
//  Copyright (c) 1938 Saka MAC OS. All rights reserved.
//

#import “AppDelegate.h”

@interface AppDelegate ()

@end

@implementation AppDelegate

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (locationNotification) {
// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}
// Override point for customization after application launch.
return YES;

}

– (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Reminder”
message:notification.alertBody
delegate:self cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alert show];
}

// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@”reloadData” object:self];

// Set icon badge number to zero
application.applicationIconBadgeNumber = 0;
}

– (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

– (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

– (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

– (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

– (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

on button click

//
//  ViewController.m
//  loclanotification
//
//  Created by MAC OS on 1/11/1938 Saka.
//  Copyright (c) 1938 Saka MAC OS. All rights reserved.
//

#import “ViewController.h”

@interface ViewController ()

@end

@implementation ViewController

– (void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.
}

– (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

– (IBAction)btnclick:(id)sender {

// Get the current date
NSDate *pickerDate = [self.datepiker date];

// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.txt.text;
localNotification.alertAction = @”Show me the item”;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@”reloadData” object:self];

}
@end

Leave a comment

search previous next tag category expand menu location phone mail time cart zoom edit close