Im developing a navigation app that using NSStream to manage a TCP connection with my server. Every time the app gets new coordinates it sends it to the server.
The problem is when my app goes to background and then suspended the stream get closed and i cant keep sending the updates to the server.
Can someone help me here? i'm pretty lost..
Try ASIHTTPRequest, It support background task.
http://iosdevelopertips.com/open-source/ios-open-source-asihttprequest.html
Related
I'm learning flutter, and I'm trying to make an app interacting with a Rust server.
I've done a bit of things already, all the basics of http requests, and simple menus and displays.
Now I would like to take it a bit further, and have the server send notifications / messages to the app even when it's closed. So idealy, I would like to have a web socket connection between the app and the server.
I've looked up some things, especially this already :
flutter : push notifications when app is closed
Executing dart in the background
But I can't wrap my head around it all.
How would one keep code running in the background ?
Any explanations on how it all work would also be great !
I am building an ios application that requires internet connection via wi-fi in order to talk to web service. Now before anything, i want my application to run a background process that checks internet availability and when connected talk to web service.
Any body knows how to implement this in background process?
I already use this solution to check whether there is an internet connection or not
Easiest way to detect Internet connection on iOS?
but I want to know how to run this process in the background in order to work even the application is closed.
You can have your checks done when in foreground. Its not allowed to for an app to execute code in background continuously(although you can execute some code when you go to background initially). If you are not planning to publish this app in app store and its a enterprise solution, then you should explore ways to stay in background by running a music file (without sound) to get CPU Cycles. It worked for me..
Now I am developing a voip app.
Is it okay to use background task to keep my app alive? so app can received incoming state to pop up a notification from the background.
I try CFStreamCreatePairWithSocket, but still can't get info from nsstream event callback.
If I use background task, App can get incoming state as it does in the front.
Thanks a lot.
Please always make sure to provide all required information to get quick help. e.g. Provide some code snippet if possible, provide information regarding which version of OS you are using etc.
Check following answer: It may help you. How to Maintain VOIP socket connection in background?
I need that my app will send some data to server every six hours for example. Purpose is that it will send request to server even when app in background. As I know only thinks GPS, Music, Push Notifications work on background. Also, as I know UIApplication method beginBackgroundTaskWithExpirationHandler: works not for a long time after app goes on background. Guys, anybody have idea how to implement this? Thanks a lot!
It's simply not possible within the limits of the current iOS SDK. The only kind of apps that can update their content regularly from the background are Newsstand apps and for them, the interval is 24 hours AFAIK and the entire updating process is largely triggered by Apple.
Unless your app falls into one of the categories you mention, the short answer is you can't. The only exception is for Newsstand apps.
But: what data would you be sending to the server if your app isn't running? If you send data to the server when something happens then the server will always be up-to-date. If the user isn't running the app then, by definition, nothing has happened and the server is still "in sync" with the client. (Yes, this potentially makes the server harder to code.)
I'm using the AsyncUDPSocket third party library in my iPhone app and for the most part it works great. I have a singleton instance of an AsyncUDPSocket that I use for all my network traffic. My app is registered for location tracking in the background and will wake up and send location update packet(s) over the network while running in the background. This all works smashingly running in the background, foreground, phone locked or unlocked, except when I do the following:
Start my app
Disable location tracking in my app settings
(so no background waking up)
Press the home button (app goes into background, socket is "freeze-dried" with rest of app)
Lock phone
Unlock phone
Resume app
Attempt to restart tracking and send something out the socket. As soon as I try, I get a SIGPIPE/EPIPE error and the app crashes.
I figured the best way to deal with this would be to close and release the socket whenever the application exits and background tracking is not enabled, but when I try [socket close] or [socket release] on the AsyncUDPSocket, I get various EXC_BAD_ACCESS errors. I've filed a bug with the dev team, but was wondering if anyone here could give some ideas on how to either avoid the SIGPIPE error entirely or other ways to keep the socket alive without releasing it. Thanks.
Great observation - yes, seems that after you send task to background and then lock the phone, sockets get dropped and next time you try to use it one gets bludgeoned with a SIGPIPE.
Ideas on how to deal with it here:
SIGPIPE crash when switching background task
(it's either set ignore for SIGPIPE for the whole app, or for the socket, or provide hanler for it)
ps. also - seems that setting to ignore SIGPIPE does not work with attached debugger, so compare with and w/o.
Just in case anyone's curious (which, judging by this question's stats, they're not), I was not able to determine what was causing the SIGPIPE error, but did eventually sort out my memory management issues (which were due to a faulty implementation of onUdpSocketDidClose in my delegate) so that I am able to reinitialize the socket each time the app restarts.