Alarm clock app in iOS

32,197

Solution 1

I agree with David. iOS built-in alarm app gets a special treatment from Apple to sound > 30 seconds while in the background. It seems to be using some private API to make it sound for a longer time even when it is in the background or closed. This is not available to other apps built outside of Apple, so don't even try to compete with it. If you buy all Alarm clock apps in the App Store (aka: approved by Apple) and try them one by one, you will see that they lack behind the built-in alarm app in the most important function of an alarm: i.e. "Sounding for a long period, in any state the app is in (active, background, or closed)"

Your best bet to simulate a background alarm is to make use of UILocalNotification for 30 seconds. If you really want to wake up your heavy sleeper, schedule to fire up five of these notifications sixty seconds apart or something like that, in the hopes they will wake up before the 5th notification ends.

Notice that with this method, your user who misses the alarm will get 5 popups on their screen when they wake up (less if they wake up during one of the alarm popups), so they'll be spending their first seconds of their morning closing those popups - not the greatest user experience.

Conclusion: Alarm Clock apps are good for foreground use only. Best Alarm app out there that will work in any state is the built-in Clock app made by Apple.

Solution 2

This alarm behavior is not available to iOS apps. You have the ability to create local notifications and add sounds to them, but the sound length is limited. You cannot have a sound continuously play such as on the built-in alarm.

One option is to repeat the alerts. So your app would send an alert, wait some time then send another. You repeat a specified number of times or until the user interacts with your app. I don't think this would provide a great user experience, so I don't recommend it.

Solution 3

I am pretty sure you can have your own custom local notification sound.

Example code localNotif.soundName = @"alarmsound.caf";

Note local notification sound will have to be of only 30 seconds or less to be played. You can get more info here.

Solution 4

If you enable the "Audio, AirPlay, and Picture in Picture" and "Remote notifications" Background Modes, you can use a silent push notification to wake up the device and then start playing audio, and as long as you’re playing audio you won’t be limited to 30 seconds to respond to the notification like usual. This won’t work if the app has been killed manually by the user, but if the user does that you could send a local notification asking them to re-open the app.

Share:
32,197

Related videos on Youtube

AmitK
Author by

AmitK

Updated on July 30, 2022

Comments

  • AmitK
    AmitK almost 2 years

    I have to create an alarm clock app for the iPhone in which user can set alarm time and sound. In doing so, I have used UILocalNotification to set off the alarm.

    Now, in UILocalNotification, first we get Notification Alert with option "Close" and "View". If the user taps on "View", then my delegate receives the application:didReceiveLocalNotification: message and the alarm sound plays.

    But in the system-native alarm app, we don't see a notification alert; it just directly plays the alarm sound. How can I have my app use this behavior?

  • heyjii
    heyjii about 12 years
    Hi, I stumbled upon this, while looking for something else. Can we specify a custom time interval to repeat these alerts when the app has gone to background
  • Farhan Hafeez
    Farhan Hafeez over 11 years
    I am sad to find this out.
  • Felix Dombek
    Felix Dombek over 11 years
    iHome + Sleep used to have this, but in 2.9 they removed it with the comment "changes in order to meet iOS compliance" ... So it seems that while it is technically possible, Apple doesn't want apps to use this feature. Shame. I'll stay with 2.8
  • Abdul Yasin
    Abdul Yasin over 6 years
    I am very sad on this. Saddest ever.