How can I implement Apple's "Snooze" functionality in their Clock app? - iphone

I'm diving into iOS development and am building my own alarm clock app to become familiar with the platform and SDK. One of the API's I'm currently learning is the Local Notifications API, which I assume is the same API Apple uses to implement their alarms in their Clock app.
What I don't understand is how they implement their "Snooze" functionality. As I understand it, Local Notifications allow you to present to the user an alert box that has at most two buttons when your app isn't running in the foreground, one button for dismissing the alert and one button for taking the user to your app. In Apple's Clock app, however, it appears the user is presented with an alert box with two buttons, one button to dismiss the alarm and one button to "Snooze" and reschedule the alarm without launching the Clock app. My questions are...
When the user clicks the "Snooze" button, how do you think Apple is rescheduling the Local Notification for the alarm without launching the Clock app? Do you think they're using their own private APIs that circumvent the limitations of the Local Notifications that only allow for two options? Or do you think they're launching the Clock app to reschedule the Local Notification, they just don't show the app launching and quitting?
The documentation says the "alertAction" property of the Local Notification is the text to be displayed on the right button of the alert box and the slider bar of the lock screen. In Apple's Clock app, however, the "Snooze" text is the left button in the alert box, nor is it the Slider bar text. Why is this backwards?
Thanks so much in advance for your thoughts!

The local notification API does not have any mechanism to do what you want. The alarm clock app is almost certainly not using any of the infrastructure for local notifications, it predates them. Even if it is factored onto some of the infrastructure provided by local notifications, it is certainly not using the public APIs.
You should file a bug requesting that this functionality be added.

Related

How to keep user notified that application is running in background?

Since few days i am searching for the functionality which will allow me keep user posted that application is running in background. I have attached a !image for what exactly i am looking for. i tried googling but could not get exactly what I need. when i tap on the flashing red bar it takes me back to the application.
Thanks in advance.
The red banner you pictured is provided by the system, is shown only if your application uses background audio recording (see AVAudioSession), and doesn't provide the opportunity for you to choose what happens when the user taps it.
Unless your app fits into one of a few specific classes, it doesn't actually "run" while in the background. Instead, it's "suspended" -- still in memory, but gets no CPU time. What happens outside of your app is thus up to the system, not to you... the only way to show a banner that will launch your application is to use a push notification service or UILocalNotification, but those banners are only shown briefly, and you don't get to control their duration. What you seem to be specifically asking for isn't possible using public API.
The kind of notification you want isn't supported by the current iOS for third-party developers.
If you want that kind of functionality then implement Apple Push Notification service through
this you can first give message to Apple push notification service. then Apple service
automatically generate notification for your App as you want.

Bringing an app from background to foreground automatically when an UILocalNotification fires?

As I understand in iOS, when an UILocalNotification fires, an alert window would pop up and ask the user to open that app.
I want to show that app to the user directly when an UILocalNotification fires, no user intervention is required.
Is it possible to bring that app from background to foreground automatically when an UILocalNotification fires?
Thank you.
This currently isn't possible using allowed public APIs on stock iOS devices.
The main logic Apple's restrictions is to protect both the user and the device(its memory, battery etc..) from harmful applications. And the logic of iOS notifications is that they let the operating system user intervention. As #hotpaw2 has said, there is no way to do that in public API's, which means if you do that your app will be rejected..
NOTE*:* If you target jailbreak devices it is possible, i can help a little too if you want that

Turn on iphone from within in app

I am writing an alarm clock app for iphone, and I want it to turn on the phone(from standby mode) approx 1hr before the alarm is supposed to go off.
Then I want the app to be active, so I can stream content live without the user having to put the phone in an active-mode.
Any way for an app to switch out of standby?
Without using private api an application can only present alertview (via local or push notification).
And only when user taps "view" button this application can be activated. You can see that in the link you provided - (second to last screenshot)
True, you can always add sound to this notifications - so alarm app can work (and there are many out there) but it can't send itself in the foreground.
Nope that cant be done, once the app went to the background state you lose control on it, and cannot bring it back
There might be a way using notifications. Check this SO question for more info:
Alarm Even Application Closed in iPhone

How to add some more custom controls in iPod background?

when we press on the Home button two times then we see the all the apps running in the background.if no apps is running in the background then there are only two controls by default.So my question is can we add same functionality in our app? means i want to add some more controls on the background. if yes then how?
You cannot add background functionality to your app.
The only ways an application can be controlled in the background are via:
Audio events. Your app registers and audio session and the user can press play/pause, next, and previous on the lock screen, task bar, or remote headphones. Unless you're doing audio-specific programming, however, you shouldn't use this.
Push notifications. Your app receives messages from a remote server via Apple's APN, triggered by one of your servers - maybe by a website application.
Sensor listening. It's possible to have your application process in the background inputs from hardware sensors, such as the accelerometer, compass, or GPS. However, this kills battery life and is discouraged unless it is absolutely necessary.
So to answer your question, no.

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.