I would like to be able to discover other iOS devices over Bluetooth while my application is in the background. Is it possible to use Bonjour or Game Kit to do this discovery while my application is not in the foreground?
Would it be possible to do this and fire off a notification if a compatible device is discovered?
Also, would I be able to run in the background while playing audio and do this detection?
This is not possible while your application is suspended. From the iOS Application Programming Guide:
Cancel any Bonjour-related services before being suspended. When your
application moves to the background,
and before it is suspended, it should
unregister from Bonjour and close
listening sockets associated with any
network services. A suspended
application cannot respond to incoming
service requests anyway. Closing out
those services prevents them from
appearing to be available when they
actually are not. If you do not close
out Bonjour services yourself, the
system closes out those services
automatically when your application is
suspended.
Be prepared to handle connection failures in your network-based
sockets. The system may tear down
socket connections while your
application is suspended for any
number of reasons. As long as your
socket-based code is prepared for
other types of network failures, such
as a lost signal or network
transition, this should not lead to
any unusual problems. When your
application resumes, if it encounters
a failure upon using a socket, simply
reestablish the connection.
However, if your application is streaming audio, it would be necessary for it to maintain network connections, so you should be able to do Bonjour discovery while in the background for an application continuously playing audio. Make sure you don't abuse this by playing a silent audio clip in a loop just so that you can stay in the background, or your application will be rejected.
Related
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.
I've a problem working with GameKit and GKSession operations.
I'm trying to implement a GKSession client-server iOS app system (ServerApp, ClientApp) having this behavior:
ServerApp creates a GKSession in GKSessionModeServer mode (Bluetooth only)
ClientApp detects the server and connects to it
Some data exchange between apps and stuff
Everything is going fine except when ServerApp or ClientApp instance goes to background.
If ServerApp goes to background, Client receives a GKPeerStateUnavailable event and i can't connect to it. What I need is to avoid this event: that means, find a way to keep ServerApp GKSession socket going even when app is in background.
Any help will be appreciated.
Perhaps you could keep the app running in the background by setting the info.plist flag to keep it alive like a music player?
This thread talks about this:
From Raaz
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.
Is it possible to mark more than one socket to keep them open in background in an iphone voip app?
According to Apple's documentation, only one socket should be configured for VoIP usage. You are free to configure multiple sockets for VoIP usage, but only one socket will be managed by the operating system when your application is suspended.
acani uses zimt websocket for chat. Can we make it so that when a user closes his phone and puts it in his pocket, he can still receive chat messages from and send location updates to the node.js server? I think this would be nicer than push notifications. Don't you? If not, why should we use push notifications instead or also?
Thanks!
You can't keep a network socket open, unless you are registered for voip/GPS/music playing in the background.
if you register for these, and then don't do them, apple usually reject the app.
the reason you cant keep a network socket open, is that without your app jumping to the foreground when it receives a connection, it cannot respond to network traffic(because if it is not in the foreground its memory content is frozen).
background network traffic kills the battery, as the radios in phones are one of the most energy intensive parts.
with push notifications, apple manage how often they are sent out, so you don't have all of the applications on the phone polling the network every 2 minutes killing the battery, you only have one active network connection, which is intermittent.