Running Background Tasks

I am new to iOS development and I have been a little stuck trying to find some information on continuing a timer in the background. I know that trying to run a timer in the background is not a good idea and that it can yield some unexpected results. I do not actually want the timer object itself to run in the background, but to have its count notify the user that it has completed its interval. I simply want to notify the user by playing a sound or vibrating or both. Then repeat this process again until the user brings the app into the foreground and stops/pauses the timer or closes the app altogether. I do not want to have a local notification appear to the user that the timer is completed.

Thank you
I simply want to notify the user by playing a sound or vibrating or both.

The only way to trigger this sort of stuff from the background is with a notification. See User Notifications and, specifically, UNTimeIntervalNotificationTrigger.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Can this be done without having the notification appear and the end of the interval timing, a "silent" notification?
I don’t understand. You specifically asked about playing sounds and vibrations. How is that silent?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
I didnt want to have the local notification that appears at the top of the screen, then disappears.

I didnt want to have the local notification that appears at the top of
the screen, then disappears.

OK, you’re mixing up terms here. When Apple folks say silent notification we mean a notification with no user interface at all, that is, no alert, no sound, no badge. Such notifications are delivered to your app and can be used by your app to update its state in the background. AFAIK this only supported for remote notifications.

In contrast, a notification that plays a sound is not silent and, as such, is supported as a local notification.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
So basically, the local notification must/will always appear and you cannot use it to trigger a background task to inform a user without visually showing the notification itself. You must always use the UNMutableNotificationContent when wanting to use the UNNotificationRequest?

you cannot use it to trigger a background task to inform a user
without visually showing the notification itself.

How would your background task inform the user of this event? You can’t present a UI from the background, or play a sound, so your only option would be to post a notification. In that case you might as well cut out the middle man.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

If I may, I have similar situations that would like to ask. I want to be able to execute some codes from background task whenever there are changes in Eventstore (calendar/reminder). I need to update data in my app (and my widget) when this change happen. How can I do this? I can't figure out how to listen to notification from Eventstore in the background.

Thank you very much, Boon

I want to be able to execute some codes from background task whenever there are changes in [EKEventStore]

EventKit has no mechanism to resume your app in the background when the store changes.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Running Background Tasks
 
 
Q