Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching ON and OFF the Alarm ios

I have prepared an Alarm Clock app which uses UILocalnotification for scheduling the alarm.Now after the alarm has been set, I want to make a switch so that I can turn it ON and OFF usingUISwitch.I just cant figure how can I do that?What I am thinking as of now is that when you switch OFF the alarm, I shall store the DATE and TIME value before canceling the UILocalnotification so that when the user again switch ON the alarm I reschedule it with the stored DATE and TIME values. Is it the right way to do or is there any other ways to do that?

like image 230
Rahul Singh Avatar asked Sep 19 '12 03:09

Rahul Singh


People also ask

Can you set an alarm on iPhone and turn it off?

The Clock app on an iPhone lets users set, edit and turn off regular alarms easily. Users can also modify Wake Up alarms in Sleep Schedules. Like all modern smartphones, iPhones allow users to set, change and turn off alarms.

How do I turn my iPhone alarm off without touching the screen?

Stop iPhone Alarm Without Tapping The Display There's a shortcut for the Stop button too. Press the Home button to abort the iPhone's wake up call without needing to look at the device. Do make sure that you use a finger that has its print registered with Touch ID.

Does iPhone alarm go off when sound is off?

If you set your Ring/Silent switch to Silent or turn on Do Not Disturb, the alarm still sounds.


1 Answers

just make the database table which have 'date', 'isCanceled' field and unique id 'alarmId' columns (use rest whatever you want). so when the user wants to cancel the alarm try this,

    NSString *alarmId = @"some_id_to_cancel"; 
    UILocalNotification *notificationToCancel=nil;            
    for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
        if([aNotif.userInfo objectForKey:@"ID"] isEqualToString:alarmId]) { 
            notificationToCancel = aNotif; 
            break; 
        } 
    } 
    [[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];

to use this better you create your alarm by,

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 

 if (localNotif == nil)  
  return;

 localNotif.fireDate = itemDate; 
 localNotif.timeZone = [NSTimeZone defaultTimeZone];
 localNotif.alertAction = NSLocalizedString(@"View Details", nil); 
 localNotif.alertBody = title;
 localNotif.soundName = UILocalNotificationDefaultSoundName; 

 NSDictionary *infoDict = [NSDictionary dictionaryWithObject:stringID forKey:@"ID"]; 
 localNotif.userInfo = infoDict; 

 [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
 [localNotif release];
like image 99
Alex Markman Avatar answered Nov 15 '22 08:11

Alex Markman