Run task in background in iOS 10 - background

Can one use UNCalendarNotificationTrigger or UNTimeIntervalNotificationTrigger to run a snippet in background in fixed interval, say once per day, without notifiying user? For example just with playing a sound and the running custom code?
I need this to calculate exact time of a special alarm in background everyday and then set notification for it.

You can't trigger a block of code to run when the notification is fired. You can, however, trigger a block of code to execute with a UNNotificationAction by adding an action to your notification and using userNotificationCenter(_:didReceive:withCompletionHandler:) on UNUserNotificationCenter.currentNotificationCenter().

Related

React Native - Execute code in background on specific battery percentage

I have a react native application where the user can choose any battery level from 15 to 100. When his battery reaches the chosen value, javascript code should be executed.
Is there a way to do this when the app is in the background? I am aware I can have long running tasks, which will be displayed as a notification to the user and I can have my code logic there.
Are there any alternatives that do not include long running tasks?
My solution for this problem to register a BroadcastReceiver in android, which will be executed every time when the battery percentage changes. It works in background and if the battery reaches a certain threshhold, a headless task can be executed which will run javascript code.

iOS: Finishing a task when entering background

If I have a large file download going on an the app gets moved to background, is there any way to keep the download executing functions alive?
I knowbeginBackgroundTaskWithExpirationHandler: gets called when the app moves to the background and I can start my task there, but I don't want to start a new task, I want to complete my old task. It can be solved with beginBackgroundTaskWithExpirationHandler:, but for that I need to pause my download and resume it from the right place, which is just plain silly.
Ideally what I want is that I wrap my download function with an expiration handler, so my download function keeps executing for the permitted time after the app has been moved to the background.
Ideally what I want is that I wrap my download function with an expiration handler, so my download function keeps executing for the permitted time after the app has been moved to the background.
This is exactly how it works. beginBackgroundTaskWithExpirationHandler: is not called when you enter the background. It's what you call to indicate that you're starting something that, if you happen to go into the background while it's running, you would like to finish. Just wrap your existing download code with beginBackgroundTaskWithExpirationHandler: and endBackgroundTask:.
It is perfectly fine to start a background thread when you're in the forground. Add your custom expiration handler. Do an asynchronous request.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[self performYourStuffInTheBackGround];
});
And a quote from AppleDEV;
you will probably want to use asynchronous network APIs. iOS provides a wide variety of APIs to do this—from low-level APIs like GCD to high-level APIs like NSURLConnection, with many stops in between—and we encourage you to use them.

Creating a Metro app which updates itself Periodically and not placed in lock screen

As mentioned here:
It seems that a background task will only run using a TimeTrigger if the user has placed your app on the lock screen.
So, how can I create a Calendar like app without background task? I mean an app which:
updates its tile Periodically (e.g. once a day)?
updates its tile even when it's not running?
You should create a maintenance trigger. These triggers will only fire once every two hours and will only fire if the machine is on AC power. When your trigger runs, you could look for upcoming appointments and create scheduled toast notifications.
var scheduledToast = new Windows.UI.Notifications.ScheduledToastNotification(toastXml, startTime);
You could update the tile as well with a ScheduledTileNotifcation() call. Unfortunately, I don't think there is a way to remove a notification so if the user deletes an appointment prior to the scheduled notification, I don't think you can remove it. I'm looking deeper into that and will comment here if I find an answer.
However, I would think for a calendar app you would want it to use a TimeTrigger and be placed on the lock screen since I would want to receive appointment reminders at any time and regardless of being plugged in or not.
Is there a reason you do not want to use the TimeTrigger?
You can schedule periodic updates of an application's tile without being on the start screen. See this article for Notification Delivery methods. Then, once the app is launched, you could update the calendar in general.

Events in rails (such reminders, stopwatch, etc)

my app has a timer (like an egg boiling timer)
The user enters a time to countdown to, and I'd like some action in a controller to occur once the timer is zero.
as requested - I'd like to have the capability of a user following several timers or timed events such as calendar. Since each user can time their events as they wish, the reminder/time's up functionality needs to give a notice to the user (by pop up message, email, etc)
using DelayedJob and whenever won't help here since they are all predefined times to events
One option to use those gems is to poll an action that will test all timers every second for all users but that doesn't scale very well or efficient..
How would I call an action exactly when the timer is up?
found what I was looking for - the clockwork gem
https://github.com/tomykaira/clockwork

how to delay application quit time in iphone sdk?

I want to register my app for push notification when my application terminates so i think if i delay my app quitting time it could be possible.Does someone knows how to delay application quitting time? I think this method
[self performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait];
will do my job but i don't know how to use this method if someone knows please tell.I need to send some data to a server along with registering for Push Notification when my app quits.
I can't imagine why you would want to do this. If it were even possible it would be extremely annoying for a user to tap the home button and the app to take x amount of time to shut down. This time 'x' being dependent on the server connection creates even more user headache.
Apple have the home button exit apps immediately for a reason.
If you want to register the Push Notifications like you suggest, do it while the app is running. If your worrying that they won't be properly set if the user exits prematurely... don't.
As users, we all know there are sometimes consequences of exiting a program without giving it time to save your settings.
For push notification it is better to register when the app first starts and then send the push token to your server in the background. However, if you have a good reason why you need to do the registration just as the app terminates, I believe you can do this if you are using iOS 4. iOS 4 has a new feature called "task finishing" that allows an app to stay running for a few minutes after the user closes it so that it may finish up any tasks it was in the middle of (such as saving data).