1) Add the following to the AppDelegate.m
-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
}
2) Add the following to your viewController.m
@interfaceViewController(){
NSUserDefaults *defaults;
//this will keep track as to whether the notification is on or off
}
3) Add the following to the ViewDidLoad
//This initializes the UIUserNotifcations
defaults = [NSUserDefaults standardUserDefaults];UIUserNotificationType types = UIUserNotificationTypeBadge| UIUserNotificationTypeSound| UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
4) Put this where you want the notifications to be turned on. Maybe an Inaction or maybe in the viewDid load
[defaults setBool:YES forKey:@"notificationIsActive"];
[defaults synchronize];
//self.message.text=@"Notifications Started";
NSTimeInterval interval;
interval = 60;
//12 hours from now
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:interval];
//Enter the time here in seconds.
localNotification.alertBody= @"This is message Users will see";
localNotification.timeZone = [NSTimeZone defaultTimeZone];localNotification.repeatInterval= NSCalendarUnitDay;
//NSCalendarUnitMinute;
//Repeating instructions here.
localNotification.soundName= UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
5) turn off notifications
//self.message.text=@"Notifications Stopped";
[defaultssetBool:NOforKey:@"notificationIsActive"];
[defaultssynchronize];
[[UIApplicationsharedApplication] cancelAllLocalNotifications];
6) Optional to display whether notification is active or not
-(void)viewWillAppear:(BOOL)animated{ BOOL notificationIsActive = [defaultsboolForKey:@"notificationIsActive"];if (notificationIsActive == true) { self.message.text=@"Notification is Active"; } }
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
localNotification.soundName= UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
}
2) Add the following to your viewController.m
@interfaceViewController(){
NSUserDefaults *defaults;
//this will keep track as to whether the notification is on or off
}
3) Add the following to the ViewDidLoad
//This initializes the UIUserNotifcations
defaults = [NSUserDefaults standardUserDefaults];UIUserNotificationType types = UIUserNotificationTypeBadge| UIUserNotificationTypeSound| UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
4) Put this where you want the notifications to be turned on. Maybe an Inaction or maybe in the viewDid load
[defaults setBool:YES forKey:@"notificationIsActive"];
[defaults synchronize];
//self.message.text=@"Notifications Started";
NSTimeInterval interval;
interval = 60;
//12 hours from now
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:interval];
//Enter the time here in seconds.
localNotification.alertBody= @"This is message Users will see";
localNotification.timeZone = [NSTimeZone defaultTimeZone];localNotification.repeatInterval= NSCalendarUnitDay;
//NSCalendarUnitMinute;
//Repeating instructions here.
localNotification.soundName= UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
5) turn off notifications
//self.message.text=@"Notifications Stopped";
[defaultssetBool:NOforKey:@"notificationIsActive"];
[defaultssynchronize];
[[UIApplicationsharedApplication] cancelAllLocalNotifications];
6) Optional to display whether notification is active or not
-(void)viewWillAppear:(BOOL)animated{ BOOL notificationIsActive = [defaultsboolForKey:@"notificationIsActive"];if (notificationIsActive == true) { self.message.text=@"Notification is Active"; } }
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
localNotification.soundName= UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Sign up here with your email
ConversionConversion EmoticonEmoticon