Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS alternative for Android AlarmManager [closed]

Tags:

ios

swift

What is iOS Swift 2 alternative to Android AlarmManager.

So far the closes thing that I found is NSTimer. But that works only when your application is up, once it goes to the background it won't work, and I need to run some function in the background and from my business logic to decide if I want to do something or not...for example if some condition is satisfied to display local notification.

EDIT

For these who have the same question, simple answer there's nothing like that on iOS.

The only workaround is to use remote pushing notifications (silent notifications) just to wake up app, and from there you can implement your business logic.

*IMPORTANT NOTE

From what I have found on few places is that people are complaining about using silent notifications to do this because your application might be rejected on app store.

If there's anyone there who is using this approach for his app on app store please share your experience.

like image 626
ShP Avatar asked Mar 11 '16 14:03

ShP


2 Answers

There is none.

As already stated in the comments, the documenation is quite clear on that:

Always try to avoid doing any background work unless doing so improves the overall user experience. An app might move to the background because the user launched a different app or because the user locked the device and is not using it right now. In both situations, the user is signaling that your app does not need to be doing any meaningful work right now.

with the following exceptions:

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

  • Apps that play audible content to the user while in the background, such as a music player app

  • Apps that record audio content while in the background

  • Apps that keep users informed of their location at all times, such as a navigation app

  • Apps that support Voice over Internet Protocol (VoIP)

  • Apps that need to download and process new content regularly

  • Apps that receive regular updates from external accessories

like image 120
Tobi Nary Avatar answered Oct 13 '22 01:10

Tobi Nary


There is no exact equivalent. Please read this: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

The relevant part:

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that record audio content while in the background
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Apps that need to download and process new content regularly
  • Apps that receive regular updates from external accessories

Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.

If the function you are trying to call does one of the above, the documentation explains how to use background tasks or other methods to accomplish that.

like image 23
Lou Franco Avatar answered Oct 13 '22 00:10

Lou Franco