GameKit keeping connection going while device screen off or in background - iphone

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.

Related

How to play sound on both speaker in iPhone programmatically during a phone call

I would like to know how to play sound on both the iPhone speakers during a call.
It is working fine when I'm trying it when iPhone is not on the call.
The actual problem I'm facing is: When i have play sound from both speaker and phone was not on call it working fine. But if iPhone is switched to a call and I am trying to play sound no sound is playing.
I very much doubt it is possible.
A telephone is an emergency communication device. The inability to make, receive or even clearly hear a phone call could literally kill someone. Consequently, the iPhone API strongly protects the integrity of the phone before all other functions.
Even if you did figure out a way, I doubt Apple would let it through. (Think of the liability issues for them and you!) The iPhone isn't a very small laptop, its a phone with a computer attached and the phone comes first.
You should always consider that when starting a design.
iOS disables an apps Audio Session during phone calls. Thus an app has no access outside its security sandbox to the mic or speaker until this audio interruption (the phone call) ends.

Sending Message iPhone to Any iPhone over Wi-fi ( Data) across world

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.

How to avoid GKSession disconnection in client-server when in background

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

Airplaying video from url to ATV using lots of battery on iphone

I am writing an app that plays a url using MPMoviePlayerController. The app works in the background and using airplay also works with an ATV, macmini using airserver and XBMC. The url is to a movie file on the local network. The way I understand is that the phone doesn't do any heavy lifting but merely passes the url to the apple tv and as long as the url points to media that the AppleTV supports then it will play.
The problem I am having is that the apple TV must be aggressively pinging the iphone and keeping the wifi active since the battery life is hit really hard. Playing an average sized movie knocks the battery life by about 2/3 on an IPhone 3GS and 1/2 on an IPhone 4S.
If I am playing on the mac mini using air server then the battery life on the phone reduces at the same rate as if the phone was backgrounded and not playing anything. I noticed that if I stop the wifi on the iphone then the movie will keep playing on the mac mini but stops within about 30s on the ATV. I am guessing the ATV keeps pushing out an event saying that it is playing and if it doesn't receive an OK in return then it stops playing.
Is there something I am doing wrong? Have other people experienced the same battery drain using airplay from their phone? I have tried someone else's app and it also did the same.
A packet trace of the traffic would give you a definitive answer. But, assuming the documentation you linked to is correct, your answer may be here:
The AirPlay server is a HTTP server (RFC 2616). Two connections are made to this server, the second one being used as a reverse HTTP connection. This allows a client to receive asynchronous events, such as playback status changes, from a server.
The reverse connection would keep the WiFi radio active.

iPod touches cannot find each other through GameKit

I have two physical iPod touch devices. If I try running a program that uses a GKPeerPickerController to find another iPod touch running the same program, they just stay at the peer picker screen without any progress. Both have bluetooth enabled. I have tried my own program, along with Apple's GKTank sample app. Neither of the iPods seem to be able to detect bluetooth devices, such as computers in discoverable mode... could this have anything to do with it?
I was able to fix this problem by restoring the software on the older iPod. I wonder if jailbreak may have caused this issue?
A couple assumptions are throwing you off:
The GameKit Bluetooth stuff runs its own protocol, which doesn't involve traditional Bluetooth pairing or discoverability.
The simulator doesn't support connecting to devices via GameKit, so you need to test this with two real devices (or two computers, as the simulator will run the GK protocol over your current TCP connection [ethernet, wifi, etc]).
The Bluetooth bring-up of TCP/IP and Bonjour is really slow, so your first connection will often take upwards of 30 seconds to do any discovery. Even then, it seems flaky to me.
Jailbreaking your iPhone puts everything in play. You should expect stuff to not work, and be grateful if/when it does.
Gamekit only work on second generation iPod Touches (and iPhone 3G and 3GS). You didn't say whether what version your touches are.
I have been getting this error throughout the development of my game. It also leads to other problems when trying to reconnect to another game as the peer picker takes ages to connect so users get impatient. Apple needs to work on getting this more reliable.
I have restored my ipods now so will be interested to see the outcome.