I'm trying to create a kind of alarm clock app with the swift but I could not figure out how to set an alarm model. I've tried UILocalnotification
but I don't want my users to be involved the flow of alarm app other than setting the alarm. Then tried NSTimer
and NSRunloop
etc. but that didn't work either since those don't work when app gets background. So is there any alternative ways to do that? Any help and suggestion would be appreciated, thanks.
Asked
Active
Viewed 2.3k times
5

Suraj Sonawane
- 2,044
- 1
- 14
- 24

Talha ŞEKER
- 157
- 1
- 2
- 13
-
If your app is in the background, there is no way to get it in the foreground without user intervention. Even with background modes enabled, the app can be in the background (and alive). So a local notification would be your best bet. – lostInTransit Jun 17 '15 at 11:56
-
same as in ObjC - please search for ObjC examples -- spoiler: it doesn't work ;) – Daij-Djan Jun 17 '15 at 12:04
-
I've searched objC examples as well but I couldnt find any solution either – Talha ŞEKER Jun 17 '15 at 12:27
2 Answers
4
I have been doing research on this for quite some time now. But didn't find any concrete way to do it. You have to use one of the following from the list and make a logic to awake the app from the background.
For the alarm you can go through the blog here. It's having the details, which you can use to make a logic with UIApplicationExitsOnSuspend in info.plist file.

MD Aslam Ansari
- 1,565
- 11
- 19
2
As already suggested, since iOS 7 the only way to have an App running in background is allowing one of the Background Modes.
You can find them in the Capabilities section in your project settings. As long as your App does not fall under one of these, you are out of luck :(...
I once tried to write a similar App to yours, and there is really no way to do that right now.
Cheers, TK

James Takarashy
- 299
- 2
- 14
-
Thank you but as far as I know background modes has their own restrictions that dont allow me to do that. In android inheriting service class gives quite much oppurtunities – Talha ŞEKER Jun 17 '15 at 12:29
-
1Correct, but unfortunately iOS has this restrictions because of battery life and performance. So as long as you wont "cheat" (like playing a sound when your timer ticks), you will not be able to write your app. – James Takarashy Jun 17 '15 at 12:40
-
1Well then how do you think the original alarm clock app of ios work? – Talha ŞEKER Jun 17 '15 at 12:54
-
6:D its from Apple, they can do more than they provide to the developers ;) – James Takarashy Jun 17 '15 at 12:55