Alarm clock app in iOS - iphone

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?

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.

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.

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.

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.

Related

Creating an alarm application for the iPhone

I have an idea for a unique alarm application on the iPhone. But at the moment the only way I can see of initiating the alarm is by leaving the app running all night getting it to poll for the current time. Is there anyway to make an app "wake up" or initiate at a certain time. I know I can use push or local notifications but they require user input before loading my app. Thinking about it I could leave my app on all night, but literally doing nothing (saving battery if not being charged) and then subscribe to a local notification for the alarm itself.
Alternatively, can I make the iPhone run my app when an alarm sounds so I don't have to deal with alarm settings at all?
No, your only option is to use either Local or Push notifications.
I think using event kit framework add event in default iPhone calender.

iPhone alarm using repeated local notifications

I'm trying to add an in-background alarm clock feature to an app I'm developing.
I have read up on the UILocalNotification object and its use, and am aware that it is limited to 30 seconds of audio.
I was thinking of scheduling multiple notifications (say, 5 of them) spaced 30 seconds apart to mimic continuous play, but the problem with this approach is that if the user hits Close, I won't be able to cancel any of the subsequent notifications.
As far as I know, it is impossible to remove or hide the Close button without hiding the notification entirely (i.e., setting the alertBody property to Nil).
So, I thought I might use the repeatInterval property to cause the notification to pop up every 30 seconds, but it seems that I can only set the interval to one minute or one second, and nothing in between.
The feature is meant to allow the user to choose between music and beeps for alarm audio; it seems I may have found a way to do the beeps - setting the repeatInterval to one second, create a second's worth of beeps (which would need to be timed to cleanly repeat) and use that as the notification sound.
However, for the music, this approach limits me to playing 30 seconds of audio, followed by a 30-second gap, followed by 30 seconds of audio, and so on.
I know that there is no straightforward solution here, from my reading of other posts and resources; no third-party app has access to the same functionality as the built-in alarm clock. I am hoping that someone has found a workaround or thinks of something really clever.
UPDATE: I have found that the repeatInterval doesn't help me in this case, as I can't cancel the repetitions without launching the app.
For the time being I have decided not to use a notification as an alarm per se, but have changed the feature to be a reminder (more along the lines of what the notification is intended for).
If I come up with a way to implement user-friendly, reliable alarm functionality to an app, I will update this post.
I am afraid you cannot accomplish this..reason being as you stated the 'Close' button. You won't be getting any call back in the app if Close button is tapped. Further even if you present notifications every 30 seconds, then there will be multiple notifications on the screen which user has to view or close. So the user experience will be crappy. I would recommended making it clear to the users that they can not set alarm with a custom sound more than 30 seconds.

iPhone OS4 alarm clock

I have read many posts and still i cannot achieve the desired functionality while my application is suspended in the background.
My reference point is this radio alarm application.
The things i cannot do using local notifications (which are successfully implemented in the radio clock above) are:
play alarm sound in the background while phone is muted
change phone volume.
play mp3 songs.
Also i noticed that they are able to play sounds longer than 30 seconds and even radio as alarm sounds which probably means that local notifications are not being used (audio-wise)
any insight would be appriciated...
The reason that this Radio App succeeds in playing a long audio file , is that it actually plays a background silent loop audio while waiting for the alarm .
IMO that's the reason people complain it drains the battery.

Is there a safe way to schedule an alert for an calendar app?

I want to make a special calendar app, but I am afraid it's not possible to safely schedule an alert for an event.
For example: I set up an alert for an event which starts in 3 months. I want to get notified 2 days before the event starts. In iOS 4 there is multitasking, so my app could run in the background all the time.
But now lets imagine it's a hardcore iPhone user who plays huge memory-intensive games all the time. At some point, iOS might kill my background app. Or the user might restart the device and forget to launch my app. So it could happen that the alert never happens. Bad thing.
Is there a safe way to ensure that an scheduled alert is thrown at the user, just like it is the case with the built in alarm clock app or the calendar app?
I'm going to bring back the EventKit notification - use event kit to schedule a calendar entry with an alert, and embed in there a URL that will open your app.
You could also use local notifications but this way the user will be able to see the upcoming event when reviewing the calendar, and even modify slightly if need be. They can't mess with a local notification once it's in place...
You want to use UILocalNotification for this.
EventKit will make it pop up in the user's calendar, maybe not what you want here.
BTW: Multitasking is really more "fast switching" than backgrounding in iOS... you won't be able to run arbitrary code in background, and you should expect to be killed anytime.

How long can an iPhone app live in the background?

I can't seem to find a clear answer to this-- I'm spec'ing out an iPhone app that I'd like to have live in the background and notify the user at certain periods throughout the day. So the user would launch the app in the morning and then continue to use their phone, then every few hours the app would pop open a notification dialog.
Will my app ever be shut down (automatically) by the OS? Or will it just live forever, notifying user when it needs to?
thanks,
Eric
Basically there are three kinds of running in the background on iOS 4:
Running in the background to "finish" stuff (e.g. upload a posting or a picture, finish processing something etc.). You ask the OS to grant you extra time after the user switches to another app, and it will tell you how much time you got. You can't run in the background for an indefinite time.
Running in the background to do specific stuff: VoIP, tracking location (e.g. for GPS navigation), or playing audio. You can only do the stuff that you told the OS you would do in the background.
Local notifications (UILocalNotification). From your description, this is what you're looking for. You're not actually running, you just schedule notifications, and when it's time to notify the user, they'll be notified and can go to your app. If you need to notify the user dynamically (i.e. you don't know ahead at what times they need to be notified and it's not location or VoIP triggered), you might want to look into push notifications.
Apple has a good overview here:
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence