My online app runs on iPhone-3GS iOS 4.3, use NSStream to communicate with server.
When I minimize the app, lock phone, and relaunch my app the streams will end.
So my app loses connection to server.
Anyone knows how to keep the connection after locking phone? Is it a feature of iOS multitask?
This is a feature of iOS. Networking connections of backgrounded apps are cut off. You need to request "VoIP" treatment: for this, you need to set the "voip" value for the Info.plist key UIBackgroundModes and then mark your socket as being a VoIP socket setting the kCFStreamNetworkServiceType of your socket to kCFStreamNetworkServiceTypeVoIP using CFReadStreamSetProperty.
See also the Apple iOS App Programming Guide, section Tips for Developing a VoIP App.
Related
I want to write a tracking application, which reacts/record when users get in a car and phone automatically pair with Bluetooth hands free. I need also Id of the hands free device.
On Android it is easy, using Broadcast Receiver your app listen to broadcasts that device had been paired with phone. It is working even after phone had been restarted and App did not run after restart.
Is it possible on iOS(7+) ?
You can do it by reading the "Performing Long-Term Actions in the Background" part of this docs
Essentially, using state restoration, the system takes note of what your app was doing when it was killed.
If the app is searching for a bluetooth device and is killed by the system, the system will take care of continuing this research and wake up the app again when the bt device has ben found.
Note that this will work only if the app is killed by the system, not by the user (using the multitask bar). This behavior has changed since iOS 7.
Alternatively, If your BT hardware can be programmed to send advertisements using the ibeacon protocol, your app can be "awakened" by the corelocation/ibeacon api. After that prompt then maybe the corebluetooth pairing code could be initiated.
I want to develop an application which sends a Message from iPhone to other iPhone over the internet, I want to receive the Message from other iPhone even if my iPhone is running in the background.
I have seen the WiTap application, but socket will get disconnect when application is closed or if there is screen lock.
So is that possible to develop the application so that I can receive the message even if my app running in the background forever?
From my little Knowledge, You can't do it through WiFi.
When a screen lock happened, device will automatically OFF the wifi connection for increasing battery life.Thats why socket connection getting disconnected.
In iOS, apps can’t do a lot in the background. Apps are only allowed to do limited set of activities so battery life is conserved.
But what if something interesting happens and you wish to let the user know about this, even if they’re not currently using your app.
For example, maybe the user received a new chat. Since the app isn’t currently running, it cannot check for these events.
Luckily, Apple has provided a solution to this. Instead of your app continuously checking for events or doing work in the background, you can write a server-side component to do this instead.
You can do it using Apple Push Notification Service.
It uses push technology through a constantly open IP connection to forward notifications from the servers of third party applications to the Apple devices; such notifications may include badges, sounds or custom text alerts. In iOS 5, Notification Center enhanced the user experience of push and local notifications.
More details are here
Note: details and screen shots are taken from raywenderlich website/blog.
is it possible to create an iphone-app, which can communicate with other iphones (with the app installed) even if the app is running in the background or the iphone is locked (=standby).
there is an app called "Bluetooth", which establishes a connection, but looses it as soon as the app is closed or the iphone in standby.
hope i am not too confusing in my explanations
My iPhone application is based on remote desktop protocol which communcates with PC using socket programming. Everything works fine in iOS4, but now i encounter an issue with iOS5 based device.
My socket get's disconnected when user presses lock button in iOS5 based devices. I have developed a cocoa based static socket library which does all communication for my iphone app.
FYI: I just call a function exposed from my library to start the communication. I call it as a background thread using
[self performSelectorInBackGround:#selector(triggerCommunication:) withObject:IP_Address];
a. Why does the socket disconnects on pressing lock button in iOS5 ?
b. Is there a way to prevent the socket from not being disconnect?
Thanks,
If we compile with iOS5 SDK, and run application, then socket disconnects on clicking lock button.
I recompiled my application with iOS4 SDK and tested my application on iOS5 based iPhone. And now socket didnot disconnect even after locking!.
Thanks
I am working on an appliction that requires bluetooth connectivity, which i use GameKit for data transfer, however im seeing that when i go in background mode, or I just turn off the screen in app, the bluetooth connection is dropped... Ive seen other apps that keep the connection alive in such situations, anyone have any idea if I am missing something that wont cause the connection to drop on such cases? Have been looking around but havent found anything useful...
Thanks
Daniel
This is not intentionally supported by Apple.
If you are writing this for an application that doesn't have to be distributed through the App Store, you can set the application up to play a silent audio file in the background. This will allow GameKit to continue to work even when your application has been put into the background or if the screen has locked.
If this application has to be distributed through the App Store, Apple require the audio to be a real feature, with audible music playing.
If you have two devices connected using GKSession and then one of them is interrupted by call or goes into background, when it wakes up connection should be still alive (you should be able to send/receive packets between devices).
You may try setting
UIRequiresPersistentWiFi
in your plist.