Hi i have to create a service in IOS OS that sends data like current location details,battery level,and other info every 15 min to the server via post api ,I understand it will not work once app is removed from app stack forcefully.But can i do something so that service will run ,background until app is killed forcefully.I know we can do only some work in background modes.Can i do someway around so that my app service always run in background
Use NSTimer and call that method which contains API call, Hope this solves your problem.
I am sure, your problem is might be solve by Apple push Kit. For this you have to need a back-end service. Generally ApplePushKit used for the VOIP(Internet calling and video call).
You have need to do following thing.
1) You have to Fire Notification every 15 Min(Pushkit notification not shown by user because it is silent never show to user).
2) You have receive controll in PKPushRegistry in method
3) You have received controll for the executed code for 30-40 second
4) Call Your API during the this time.
Related
I'm developing an application with SWIFT, which sends the location of cars through a REST call. When the application goes to background after 7 minutes, the loop that is sending the location stops being sent.
Does anyone know of any way to keep the loop running?
In the documentation it informs that this is a normal behavior .. but it needs to continue making this call of REST.
You may need to enable "iOS background data transfer". Check here an article on this topic: https://topologyeyewear.github.io/engineering-blog/2017/11/20/background_transfer/
Good luck!
My requirement is, I need to call a Web-Service and the count of the data should come on the local notification content on daily at 8 AM
example : you have 10 new notification, the 10 is the count of the data in an array.
Some one please help me to do this.
Thanks in advance.
you cant schedule something like this offline but you have 2 options that differ
with thr app background refresh API you may come close. If you opt in to that api, ios will wakeup your app when it has spare cycles and will give you cpu time to run some code and allow you to do this.
the background refresh api was meant for 'periodic' updates like this IMO. What you cannot do with it though, is schedule any EXACT times/dates/intervals you want to be woken. You can recommend times to ios but it may or may not stick to the plan (this depends on device use .... battery .... time of day...... etc)
another option are a backend that sends 'silent' push notifications at your required time. IOS would wake your app for those notifications and as they are silent, the user wont see it.
you can have a backend send you non silent pushes. Your app will be launched on tapping the notification and you can do whatever you like
==> option 1 works offline, option 2 and 3 require connectivity and even worse a decdicated backend to support it. IMHO option 1 is often very good and underrated.
In my app I need to call an API service when there is significant change in the user's location. So I'm using startMonitoringSignificantLocationChanges method and handling the API call in the corelocationdelegate method(locationManagerdidUpdateLocations). When app is in background or active state I can call API without any hesitation.
The problem comes when app is in suspended state. I know when SignificantLocationChange is triggered iOS wakeup the terminated app gives small amount of time to manually restart location services and process the location data and in this case we get call back to the delegate method, do I need to use background task to call the API or API call should be made as before(as incase of active state). Currently the API call takes around 6-7 seconds. If it takes more than 10 seconds how do I handle the API call?
One more question, is there any problem if I don't call stopMonitoringSignificantLocationChanges? as my app always need to call the API when there is significantLocation change in user's location.
When you say "...I need to call an API service..." are you talking about making a network call to a server? If so, then yes, you should ask for background time.
I seem to remember you only have about 30 seconds of background time, and network calls can take unpredictable amounts of time.
You want to make the call beginBackgroundTaskWithExpirationHandler, and then call endBackgroundTask once your server call is complete.
I am new to IOS and wants to used Local Notification feature of iOS.
my problem is i do not know if i can go with local notification. in my case data will come from web service... it is like..no specific date. default time interval is 60 Sec. after 60 sec app has to call webservice which will return notification data..and after some validation i need to push to user.
and if user click on view details it will launch appand get data via webservice.
Is using localnotification will serve my purpose? or i have to go with other approach?
Please help.
Thanks in advanced.
I think this 60 second thing is you polling the server every 60 seconds to fetch new data, then if there is new data post a local notification?
This is kinda possible with iOS7 but not exactly every 60 seconds, sometimes not at all, But in general it is strongly frowned upon. Instead the webserver should send push notifications when new data is available, It saves the user battery life.
On iOS7 there are silent push notifications (just don't include the alert) that can ask the client to do the validation you mentioned, and If the user needs a notification you can create a Local Notification to alert the user in a change
You should give this documentation a long look, it isn't trivial work for a new iOS programmer:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html
And here is a relevant Apple documentation quote "Local and push notifications serve different design needs. A local notification is local to an application on an iPhone, iPad, or iPod touch. Push notifications—also known as remote notifications—arrive from outside a device. They originate on a remote server—the application’s provider—and are pushed to applications on devices (via the Apple Push Notification service) when there are messages to see or data to download."
If you are trying to achieve this functionality to happen automatically/polling (i.e without user interaction like, clicking on the view details button)- the answer is a big NO at least not till iOS6.x
Your application cannot run for infinite length in background at-not till ios6.x. You may have to consider using APNS service to achieve this.
Otherwise, your approach on scheduling a local notification for ever 60 sec - The user clicks in the view option - the application comes up - You make a web-service call - Get the data - Validate the received data - Uploading to the server, looks fine to happen.
Will it not be annoying to the user getting notification for ever 60 sec & operating on the app to do whatever you intended to do? - Just curious.
It's generally a common question.
I wonder how do mail apps implement functionality of email-receiving?
I need to implement a simple sync between two devices(for example) using my web service.
Imagine a to do list app.
Is it possible to implement such a functionality: device1 makes an entry,then sends a message to webservice, webservice informs device2 that changes took place and device2 adjusts its data and displays that entry?
On iOS what you want could easily be implement with push notifications.
As soon as the server detects changes that device2 needs to be aware of the server will send a push notification to that device.
After the user views the notification the app should update it self, it would also be a good idea to let the app update it self when coming to the foreground.
The reason for doing it with Push Notification and not polling is that if your app is in the background you can only continue to run a process for 10 min max. You might get around this by adding the background mode to your app, like VOIP, Audio or location. But if you app does not fall in those categories apple might reject your app.
With Push notification the device will receive the notification even if your app isn't running or in background.
Basically there are 2 ways:
polling, each device asks the webserver for changes every N minutes: new todo, delete a todo, change a todo, ... and then each device will adjust. The frequency of the poll depends of the level of real time you are looking for. It can be 1 call every second or every 12 hours or much more.
implement a kind of BOSH protocol: the device opens a connection to the server. The server keeps it open until there something new to send to the device or the connection times out. In that case, the device reopens it.
Option 1 is better for your todo app because you don't need real-time accuracy. The option 2 is better for a chat application where you don't want to wait for the message.