iOS iPhone GKSession discovery in background - iphone

I know that the system can close Bonjour sockets while the application is suspended.
But ,will the system allow me while my application is in the background to only discover other devices not creating sockets to them and perhaps store those devices in a list or something like that ?

Use UIApplication's method
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler
you can run your code in background up to 600 seconds on iOS 4.x and later versions.

Your app can only run in background for audio, voip or location. So there is no way other then the previous mentioned methods to run an app in the background.

Related

app runs in background on ios4

I hope to run an app in background on ios4
I know
Apple allows only certain types of apps to run in the background, like navigation and audio and VOIP apps. But even those are limited to only the necessary tasks.
Is it possible I register the app as one kind of VoIP, Audio or GPS apps to keep it run in background?
Welcome any comment
You can't "run" an app in the background; you can only run a task in the background. The tasks are
Continue Playing Audio
Maintain VoIP Connection
Update Location (GPS)
Some Finite Task (such as uploading a file)
I haven't developed for iOS so there might be something I'm missing. Read more at Executing Code in the Background. As of iOS 4, developers don't have the ability to implement true multitasking. Correct me if I'm wrong in any of this.
Not in general, no. You could register a VoIP or GPS session and abuse its callbacks for certain tasks, but I doubt the App Store review process would take kindly to it.
What do you need to do in the background that isn't covered by task completion or the audio/VoIP/GPS background modes? it might be possible to use another paradigm and still get the cake.

Can bluetooth be used with iOS Multitasking?

I'm thinking the answer to this is no, but does anyone know if a Bluetooth connection can be maintained in the background with iOS? I'm thinking I might be able to keep it around with the finite-task background API, but I haven't found anything indicating whether that's true or not. Another option would be to use GPS notifications and just reconnect every time the app gets a location changed notification.
You a right. It's a NO.
But if you use location change notification to wake up your app, you may have a short period of time to use Bluetooth.
I think that the Bluetooth connection should be maintained, but if your bluetooth application is not the foreground application it will not receive any data / commands, when it becomes foreground it will.
It is possible, I use this trick to allow an App to use foreground APIs for iBeacons to allow the app to range even when the App is in the background.
To range for iBeacons it uses a high power API and as so this is restricted to only run when the App is in the foreground and stops all delegates being called once the App enters the background.
By playing a silent audio file and adding the AirPlay capability to your plist it allows your app to run in the background just as it would if it was in the foreground.
I'm not sure if it will work for your case but as iBeacons do use the Core Bluetooth and Core Location frameworks it might just do what you are asking.
http://yifan.lu/2013/12/17/unlimited-backgrounding-on-ios/
Note although this trick has not been patched by Apple in iOS8 beta 5 it is possible they will in an update.
If you're using iBeacons, there are built-in APIs for handling when you enter/exit a beacon region, and you typically get ~5 seconds to range for beacons at that point before the app is put to sleep. Theoretically, you could start a background task w/ expiration handler that might allow you to range for ~30 seconds while backgrounded, but I have not verified this is the case. I do know that the background task can be started when normal CLRegions are entered/exited while in the background, and there is functionally no difference between CLRegions and CLBeaconRegions in terms of region monitoring, so if I had to guess I would say this is more-than-likely possible.

iPhone:How to create thread running in the background always?

I want to initiate a separate thread apart from main thread and do some operations continuously even when my app is closed. I tried detachNewThreadSelector, but it doesn't work continuously and that too it needs my app to be launched.
And whenever I don't need it, I want to stop the thread as well. It is possible in Android, don't know how to do in iOS. How can I achieve it, could someone guide me on this? I am developing on iOS 4.3 SDK.
You can't create a thread on a stock OS iOS device that will run in the background always. Some types of apps, such as for VOIP, audio play/record and GPS monitoring, can register for callbacks when the app is in the background.

How does skype remain on top when call is in process and you switch to other app in iPhone

what iOS feature does skype app use where it can remain on top of other apps with a drop down like bar even if you run other apps?
Skype uses the iOS 4 multitasking APIs, specifically VoIP multitasking in order to keep the call active while the rest of the app is suspended.
When the app is sent to the background, Skype informs the system that it would like to keep its network connection alive and that the audio subsystem should remain active.
The system continues to look after the network connection, passing received data back to Skype in order for it to process the audio.
This is one of the three main forms of multitasking in iOS, the others being: audio streaming, like Pandora and location services, like Tom Tom navigation.
It does this via the background execution APIs available starting in iOS 4. More information about how it works can be found in the Implementing a VoIP Application subsection on this page in the iOS Application Programming Guide.

Can an iPhone application detect the execution of other applications when it is in the background?

With the support of multitasking in iOS 4.0+, is there any way that I can have my application run in the background and detect the launching and exiting of other applications?
I know you can do this in Android, but I was wondering if this was now possible on the iPhone.
iPhone's backgrounding feature puts the process to suspension which the user code can no longer control the app until it becomes active again. Therefore, even if another app is launched or exit, the backgrounded app cannot catch the notification.
(Anyway, to detect whether an app with ID com.yourcompany.foo becomes active or suspended, you could listen to the com.yourcompany.foo-activated and com.yourcompany.foo-suspended Darwin notifications.)
Under the stock iOS, apps don't run in the background, only specific allowed tasks do (audio, VOIP, location logging, etc.)