Can I customize Task Scheduler for iOS?

I want to create an application in which I can have a job (GET url) executed at predefined times (selectable in the UI). For example, Monday through Friday at 8 am.

Is this possible in iOS?

I tried searching but didn't find anything useful, possibly using the wrong search terms. Does anyone accidentally come across some sample code for what I'm trying to do?

Edit: Indicate that I want the application to perform these tasks even if the application is not running. I want the user to just highlight the desired days of the week and times, and then the phone takes care of everything - even if the phone is restarted.

+3


source to share


3 answers


If you want to wake up regularly to download content, you can register to receive push notifications and download based on the content of the notification. You will probably get a few cycles to do this close to the scheduled time. If you want to "opportunistically" download content, you can register for a background "fetch", but there is no planning guarantee.



See https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

+4


source


So, first of all, the application must be open for any task. After that, there are two ways to do it:

You can set the timer with a selector, or you can use a grand central dispatch. Both have their strengths and weaknesses depending on what the task is ...

https://developer.apple.com/Library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/index.html



https://developer.apple.com/library/ios/documentation/performance/reference/gcd_libdispatch_ref/index.html

check these links and see if they can help.

Remember that you have to do this kind of thing on a background thread and that the UI cannot be updated with any thread on the main thread. Also, be aware of the restrictions that iOS uses in background apps.

+1


source


Yes it is possible. You can use -

[self performSelector:@selector(myFunc:) withObject:nil afterDelay:5.0];

      

0


source







All Articles