How can make my iphone application is working both single tasking and multitasking.
Like if suppose in my application is working finely in latest multitasking supporting devices.
But it was not working properly in single-task supporting devices..
In single-task supporting devices during run time if suppose i pressed the exit button it will not support multitasking ..
How can solve this problem..
It depends on what your application is doing. If your application does not post local notifications to itself, or handle external notifications, then all you may need to do differently between single and multitasking is to save your user data and important state in the
- (void)applicationDidEnterBackground:(UIApplication *)application
method to handle multi-tasking iOS's, in addition to the
- (void)applicationWillTerminate:(UIApplication *)application
method which will handle the single-tasking versions. If your application is not killed while in the background in a multi-tasking OS then it will resume exactly where it was suspended, unlike the single-tasking OS where you must save all state and restore that state manually.
Related
I'm running into a bit of an issue.
My software needs to know when the application is in background so it will disconnect from the server, and start receiving push notifications.
For that I use UIApplicationDelegate's method :
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationWillTerminate:(UIApplication *)application
The problem is, when a jailbroken device is using the "tweak" called backgrounder, that will force your application to stay active and not going into background, none of the UIApplicationDelegate's method get called when we click on the HOME button.
The thing is, each client connected in SSL cost me a lot of memory on the server. I do not really care that the device is jailbroken, or as a matter a fact, the application will run indefinitely on the device. But I would like them to disconnect from the server when the application is no longer on the screen, but I can't seems to find any method that will inform me of such operation when backgrounder is installed.
Solution find : check my own answer on the post
The best thing to do would to eat up A LOT of memory so that way the jail breakers would have to quit your application! Just kidding of course. The best option is to wait for inactivity on the user's side. For example: 1. Check if the device is jailbroken. 2. Check if backgrounder is installed (I am not sure if you can do this but I am pretty sure you can). 3. If the user is all those things wait for them to be inactive for, lets say, 30 seconds and then disconnect from the server.
Do none of those methods get called at all in your app when Backgrounder is installed, or only when your app transitions to the background? If they never get called at all, then the solution is extremely simple: Set a timer for, say, 10 seconds, when your app's application:didFinishLaunchingWithOptions method is called, and when that timer expires, if applicationDidBecomeActive: has not been called, then you know that the user is using Backgrounder.
If they do get called on app launch, though, then things get trickier. I'm not aware of any direct methods to detect if a tweak like Backgrounder is installed from within the sandbox. You could simply check if the device is jailbroken (there are a number of ways to do this, they should be easy to find), and add a timeout period for your server connection if so.
Milk Tea got me on the right track... So the bounty goes to him.
But actually I got a better solution...
I have checked every single notifications thrown when resigning the App...
and I got this, even with backgrounder configured to keep the App open, those notifications are thrown :
UIApplicationSuspendedEventsOnlyNotification -- When going into background
UIApplicationResumedEventsOnlyNotification -- When going into foreground
This makes sense, since even with backgrounder, it would have been a bad idea to let the App keep receiving events notifications, for example, when a change of rotation (or a shake) is done outside the App. Do you imagine every App doing a rotation on background everytime you move your iphone ?
My app connects to a Bluetooth sensor then starts updating the UI based on the notifications sent from said device. I am having a problem with IOS automatically generating a large amount of notification pop-ups when the app is minimized, I think this is due to the frequency at which the sensor is sending data. So I am trying to figure out how to keep the user from being bombarded when they minimize the app. I am trying to tell the device to stop sending data, but I suspect that delegate method never gets called.
I have tried adding
[application cancelAllLocalNotifications]
to both
- (void)applicationDidEnterBackground:(UIApplication *)application
and
- (void)applicationWillResignActive:(UIApplication *)application
but still seem to have an issue, any ideas.
Thanks
You can use CBPerpheral::setNotifyValue:forCharacteristic: to start or stop getting notification from the said peripheral.
Another option is to use session backgrounding. For that you need to add the bluetooth-central backgrounding mode to the app's plist file. After that the app is going to receive the bluetooth communication events both in foreground and background and no notifications will be generated by iOS. If your app decides it needs a notfification, it can simply generate a local notification (tutorial).
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.
Is this now a mandatory requirement before uploading to the app-store? As I understand it, making my app compatible with multitasking is something extra that I need to implement. (?)
No.
It's not something extra. It's an opt-out process. Read this Apple doc.
My personal opinions is that if you don't actively support multi-tasking, you should opt-out from it.
Your app does not need to take advantage of the multitasking features, but it DOES need to gracefully handle being put in the background and never receiving a notice that the application will quit. More specifically:
Under previous versions of the OS when the user quit the app (by pressing the home button) the App Delegate's
applicationWillTerminate
was called. Under iOS 4 pressing the device's home button instead puts the app in the background, calling the App Delegate's
applicationDidEnterBackground
When the app is brought to the foreground again the OS call's the App Delegate's
applicationWillEnterForeground
This most commonly caused trouble for older apps when state changes -- user preferences, data files, high scores, etc. -- were being written out and saved when applicationWillTerminate was called. Now that it's no longer being called, some apps fail to save user information.
Most anything that you were doing when applicationWillTerminate was called should now also be placed in applicationDidEnterBackground, depending on what your app does.
Additionally, it's possible that some things you were doing in application didFinishLaunchingWithOptions will also need to be done in applicationWillEnterForeground, depending on what your app does.
It is not mandatory to support multitasking.
To disable multitasking, you can use the UIApplicationExitsOnSuspend key in your info.plist file, which may appear as "Application does not run in background."
See http://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html for more information.
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.)