Reminder is not working - ios

I want to remind the user based on time,but cannot achieve using this code,please give me any solution.This is my code:
NSDate *pickerDate = [self.StartDate date];
UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];
NSDate *date1=[pickerDate dateByAddingTimeInterval:60];
notifyAlarm.fireDate = date1;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
//notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval =NSCalendarUnitWeekday;
notifyAlarm.soundName =UILocalNotificationDefaultSoundName;
notifyAlarm.alertBody =self.EventText.text;
//notifyAlarm.alertLaunchImage=#"in.png";
[app scheduleLocalNotification:notifyAlarm];
[self dismissViewControllerAnimated:YES completion:nil];

Write this code in didFinishLaunch method in appdelegate.m
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}

Related

My simple UILocalNotification is not firing

-(void)setNoti {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];
localNotification.alertBody = #"NOTI 1";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
localNotification.repeatInterval = kCFCalendarUnitMinute;
NSDictionary *dict = #{#"nid":#"1"};
localNotification.userInfo = dict;
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
}
Why my simple UILocalNotification is not firing?
Have you added this code in didFinishLaunchingWithOptions of AppDelegate
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
I am not sure you added or not, but if you missed this, you will never get local as well as remote notification.
You have To Register Notification setting For Local and Remote Notification both Please Register notification setting First.

Local Notification Not Firing With Background Fetch

Can someone please take a look at the following code and tell me why the local notification isn't firing. Im running the app in XCode and using the debug option to simulate a background fetch but the local notification doesn't fire.
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(#"performFetchWithCompletionHandler");
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.alertBody = #"Update demo text!";
localNotif.alertAction = #"OK";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.fireDate = nil;
NSLog(#"Local Notification");
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
//Perform some operation
completionHandler(UIBackgroundFetchResultNewData);
}
Do you query the user to allow push?
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:settings];
}
Instead of checking device version, use below code that checks RespondToSelector:
if ([UIApplication instancesRespondToSelector:#selector(registerUserNotificationSettings:)])
{
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

local notification in an application

I am stuck with the strange problem. I am making an alarm application.When i fire a local notification it works fine in simulator but when I compile the code in an iPhone it dose not working.Same code is working on an simulator and not responding on a iPhone.
notification code:
-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = fireDate;
localNotif.alertBody = #"Time to wake Up";
localNotif.alertAction = #"Show me";
localNotif.soundName = #"Tick-tock-sound.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.repeatInterval = NSCalendarUnitWeekOfYear;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
and save button code is:
- (IBAction)saveBtn:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone localTimeZone];
NSLog(#"time is %#",dateFormatter.timeZone);
dateFormatter.timeStyle = NSDateFormatterShortStyle;
NSString * dateTimeString = [dateFormatter stringFromDate:timePicker.date];
datesArray = #[[dateFormatter stringFromDate:self.timePicker.date]];
}
Please tell me the solution. Thanks
Write this code in appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
// Register for Push Notifications before iOS 8
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
return Yes;
}

UILocalNotification removed automatically

I am working on VOIP iOS app in which i have to show a local notification when call comes and app is in background mode i make it like this
Register Notifications in appdelegate
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
showing Notification
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
UILocalNotification* localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.alertTitle = #"Call From";
localNotif.alertBody = [NSString stringWithFormat:#"%#", callerName];
localNotif.alertAction = #"Receive";
localNotif.applicationIconBadgeNumber = 1;
localNotif.fireDate = [NSDate date];
localNotif.userInfo = #{#"name":callerName};
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
}
the local notification show as alert on top but when user not attend the call or other user disconnect the call, local notification removed automatically from Notification centre which is very weird, i googled too much but no success suggest some solution.
Thanks in advance.

Local Notification not working iOS 8

I want to fire local notification on particular time daily, i have wrote this code snippet but it is not receiving notification.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// running on iOS8
if ([application respondsToSelector:#selector(registerUserNotificationSettings:)])
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:settings];
}
else // iOS 7 or earlier
{
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
NSLog(#"didReceiveLocalNotification----");
application.applicationIconBadgeNumber = 0;
}
//ViewController class
- (void)viewDidLoad
{
[super viewDidLoad];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:7];
[dateComponents setMinute:59];
NSDate *currentDate = [NSDate date]; //2015-04-13 07:56:09 +0000
NSDate *fireDate = nil;
fireDate = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents
toDate:currentDate
options:0];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotification.alertBody = #"Notiication success....";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
My Log shows didReceiveLocalNotification but notification not appearing in device :(
Where i am making mistake please help.
Thanks in advance
The notification won't appear while app is in foreground. The notification will show up only if the app totally close or in the background.

Resources