Making the app give an alert without running in the background or using notifications? - iphone

I'm wondering if it's possible to make an iphone app give the user an alert in a certain time without being run in the background or using notifications?
I see it happening in an app called iPray Pro. It gives an alert for the prayer time even though it's not running in the background or using notifications. I checked under the Setting-Notifications and the app is not there at all.
How is it done?

Scheduled local notifications will trigger even if the app is closed. iPray probably schedules notifications for a given time which are then triggered by the OS without the app having to be open.

Look for Local Notifications in the iOS documentation. They are like push notifications, but don't require a server. They are quite simple API to use too; make a UILocalNotification and use the scheduleLocalNotification: method on UIApplication to add the notification onto the system.
It will then fire in accordance to the fireDate property of the local notification you scheduled.
Local Notifications require iOS4.0 or later.

It is using Local Notifications, not Remote Notifications.

Related

iOS, Can I schedule a local notification and notice it in AppDelegate with the app running in background?

I'm using local and silent remote notifications in the app I'm working at work. I need to launch some methods according to events received from our servers or from the app itself via silent remote and local notifications respectively. I have no problem with remote notifications with the app in foreground, background or with the notification touched but I can't get the scheduled local notifications to be noticed by AppDelegate if the app is running in background (I mean, without user tapping the banner).
Is this even possible? If yes, which parameter should I add to the notification or what method is supposed to be called when it arrives?
I don't think it's possible to send a local notification that runs silently and starts your app. The normal way to do things like this is Background App Refresh:
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/updating_your_app_with_background_app_refresh
You have no control of the time. iOS will periodically give you short slices of time

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.

How to invoke a method daily at a specific time in iPhone application?

I want to invoke a method daily at a specific time in my iPhone application.
How can I achieve this?
There's not a whole lot you can do with the iPhone SDK and a closed app. You can have it send local push notifications at specific times, but that won't execute your code until the user manually opens your app.
See this related question recently asked: Is it possible to have my closed app run code in iOS?
One thing I've seen apps do (like alarm clock apps, etc) is have you leave your app open and just let the phone fall asleep and then it will still execute code when you want it to. But that only works as long as the user doesn't hit the home button.
Schedule a local notification. This is how most basic alarm apps work. The app needs to be running sometime before the method execution time to schedule a local notification. After the local notification has been scheduled, the app can be closed and the method will be invoked at the specific time.
If you have push notifications configured, then your app does not need to run at all to schedule the method. It can all be done from another application.
Check out this documentation on local and push notifications from Apple.
you cannot run a specific code inside your application when its not running ..iOS allow only limited functionality to be run in background or when app is quit.

Is cancelAllLocalNotifications App specific or for all local notifications

I'm working a bit with local notifications for the iPhone. All well so far and I'm just seeking confirmation about the cancelAllLocalNotifications.
Would it be correct that firing off a cancelAllLocalNotifications would cancel all SCHEDULED notifications ONLY FOR THIS APP?
E.g other (non scheduled) notifications in this app would still work and scheduled notifications in other apps would still remain. My logical mind say it should be so, just want to be sure.
Thanks
All calls to the local notifications API are restricted to the subset of notifications that your app has created.
cancelAllNotification cancel first 64 notification of the system scheduled by application.

Can I use Push Notification for this

My app should post some message to Twitter at the end of each day at the time X. App might not be running at this time X, but it still has to post that message. I don't want to bother user by everyday asking to do this task.
Can I use Push Notification to silently (without any alert view popup, sound or anything else) do some task in my app in some constant time everyday even if it's not running?
thx
There are three 'notification' mechanisms you can send via push: alerts, sounds, and badge values. The way the push notification works is that on the phone it launches the app and hands over the 'push payload' to it with those values. Even if you turn off all three mechanisms, the OS will still have to launch your app each time, which means the user will get interrupted.
In short, you can't have a push happen silently. I doubt, from a user-experience point of view that Apple will allow things to happen on the phone without the user getting notified somehow.
No.
You can't schedule things to be run by your app on a non-jailbroken iPhone.
The only solution is to have a separately hosted service somewhere to which you push details from your app and that runs the scheduled updates on your behalf.
To do so silently is not up to you. The iPhone device has a configuration in which each app with a Push mechanism has settings where one can specify if they want alerts or not. If set to yes, the text of the alert is displayed as well.
sounds like you are trying to "wake up" your app at a specific time each day to perform some type of task. from what i understand about the iPhone this is not possible. you cannot create a cron job or something that will fire on a time you specify. you can run this on the server side and then push a notification to the user telling them that the message has been posted to twitter.
if you are on a jailbroken phone i feel confident that there is some way to do this.
Given that push notification requires that your server send a notification, why not skip a step and have the server just send the update directly to Twitter on the user's behalf? You can't use push notification to trigger an automatic task on the iPhone like you're asking - the user must take the step of accepting the notification for anything to happen.
if you really want to do it from the phone, you can just declare a "long term" background task should be covered around here (iphone app programing guide) some where..., that way you never go sleep, and you can do what ever you like... :)