Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
755 views
in Technique[技术] by (71.8m points)

cocoa touch - Call a web service from iOS at a particular time daily in the background

Is there a way to schedule a function which calls a web service at a particular time on a daily basis?

According to my research, I will have to use local notifications or NSTimer to schedule or call the function at a specific time. But I need this to work whether my application is in the background at the schedule time (and not running any background task), or in the foreground.

There are two cases: 1. Location service is running in the background in my application 2. No location or background service is running, or the app is in the suspended state (if the user disabled location updates)

But I have to send some status to my server at the scheduled time daily.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have the following options.

  1. Silent Notification : A silent push notification is pushed from the server, indicating that now is the time, you need to call the webservice and further do the necessary tasks. You will have around 30 seconds to complete the task. Now notice that during this it is not necessary that your app is opened, as this will be done in the background, without your app not opening.

    Follow this link here to configure your project with silent notification

  2. Location based (Geofencing / Location Change) : Well you manage your app by giving it a location, that whenever it enters/ exists / location is updated near to / on that particular location, the app even if terminated, will be launched in the background.

    applicationDidBeginLaunchingWithOptions will be called with a specific key notifying that this app was launched from a location change.

    Follow this link to configure your app accordingly. Now the caveat here is this wont depend on time, but rather a particular location or locations, whichever suits you.

  3. UILocalNotification or Push Notification : But in both cases, its no guarantee that user will interact with the notification banner and open the application in the first place.

Hence in the first option, you can do the work without the user interacting with the device (Device has to be connected to the internet) on Time based and Location based changes and in the second option User has to interact with the device (notification banner). Please choose the one best for your requirement.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...