2

Currently i am using Xcode 7.2

I have an requirement like: Actually i want to schedule a daily notification (only twice a day) at 8:00 AM & 8:00 PM.

I am new to usage of Local notification. I did some R & D i found some links also like: Daily UILocalNotification firing more than once . But i am unable to solve my issue....

If either the app is in Inactive/Active/Background/Suspend i need to show the Local notification to specific user.

How can i overcome this issue?

Community
  • 1
  • 1
Mannam Brahmam
  • 2,225
  • 2
  • 24
  • 36
  • I have just answered a question like this http://stackoverflow.com/questions/36126988/swift-ios-localnotifications/36127083#36127083 – Twitter khuong291 Mar 21 '16 at 10:27
  • Hi @ Emil, I am developing an app like Health info (Doctor Recommended & Actual Values like (BP, Sugar, Heart Beat and etc..,)). I need to inform user daily at 8:00 AM & 8:00 PM. these intervals and user should re-enter those values – Mannam Brahmam Mar 21 '16 at 10:30
  • ThanQ @ khuong291. If you don't mine can you please post answer in Objective-c and in which method i have to call you're code.. My requirement is like: Inactive/Active/Background/Suspend i need to display notification.. – Mannam Brahmam Mar 21 '16 at 10:32
  • are you using swift or Obj-C? – Lorenzo Mar 21 '16 at 11:19
  • Hi @ Lorenzo, I am using Objective-c – Mannam Brahmam Mar 21 '16 at 11:20

1 Answers1

2

Notification For Morning 8:00 AM

UILocalNotification *localNotif1 = [[UILocalNotification alloc] init];
localNotif1.alertBody = @"Morning 8:00 AM";
NSDateComponents *components1 = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:[NSDate date]];
[components1 setHour:8];
[components1 setMinute:0];
localNotif1.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components1];
[localNotif1 setRepeatInterval:NSCalendarUnitDay];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif1];

Notification For Evening 8:00 PM

UILocalNotification *localNotif2 = [[UILocalNotification alloc] init];
localNotif2.alertBody = @"Evening 8:00 PM";
NSDateComponents *components2 = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:[NSDate date]];
[components2 setHour:20];
[components2 setMinute:0];
localNotif2.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components2];
[localNotif2 setRepeatInterval:NSCalendarUnitDay];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif2];
mital solanki
  • 2,394
  • 1
  • 15
  • 24
  • ThanQ @mital solanki, I am new to this Local notification concept. If you don't mine In which method(Delegate or other) i have to call these methods?. It should be work in Inactive/Active/Background/Suspend – Mannam Brahmam Mar 21 '16 at 11:53