IPhone - UILocalNotification as Alarm

Even when my iPhone application is in the background, how can I use UILocalNotification to display my abram every day at 8:00 pm?

+1
source share
3 answers

Set fireDateat 8:00 PM and set repeatIntervalto NSDayCalendarUnitand schedule an alert using[[UIApplication sharedApplication] scheduleLocalNotification: myNotification];

+3
source

The daster answer is correct. just wanted to add to it that the alarm will not sound if your device is in silent mode. This is Apple’s limitation for UILocalNotification.

+2
source
UILocalNotification *localNotification =[[UILocalNotification alloc]init];

 NSCalendar *calendar=[NSCalendar currentCalendar];
    [calendar setTimeZone:[NSTimeZone defaultTimeZone]];

    unsigned currentFlag=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSWeekdayCalendarUnit;

    NSDateComponents *comp=[calendar components:currentFlag fromDate:[NSDate date]];

    comp.hour=8;
    comp.minute=0;
    comp.second=0;

    NSDate *date=[[calendar dateFromComponents:comp]dateByAddingTimeInterval:0];

    if (localNotification==nil) {
        return;
    }

    localNotification.fireDate=date;
    localNotification.timeZone=[NSTimeZone defaultTimeZone];
    localNotification.repeatCalendar=[NSCalendar currentCalendar];

    localNotification.alertBody=@"Good Morning dude..!";

    localNotification.alertAction=@"Snooze";

    localNotification.repeatInterval=NSDayCalendarUnit;

    localNotification.soundName=@"goodmorning.caf";

[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

, ...!

0

All Articles