In a cocos2dx project, on iOS 10 devices, when the notification center is swiped down then up, a huge frame rate drop happens. As a result, when the animations resume ui elements whose motion depends on the delta t are moved to invalid positions. It looks to me that the OS is putting the app in some kind of a background mode but the applicationDidEnterBackground is not called.
Is there a way to receive an event when the notification center is swiped down/up?
Use
applicationWillResignActive(_:)
The above delegate gets called when ur app leaves foreground. This is the same delegate that gets called when ur app momentarily looses focus like on receiving call etc.
You can use
applicationWillEnterForeground(_:)
to figure out when ur app regains the focus.
read : https://developer.apple.com/documentation/uikit/uiapplicationdelegate
As these delegates are called on App's UIApplicationDelegate which is typically ur appDelegate file and most of the times you would like to get notified of these events in individual ViewControllers rather than in AppDelegate you can always use NotificationCenter and add observer for UIApplicationWillResignActiveNotification
read : How to access UIViewController's varaibles inside "func applicationWillResignActive"? Swift, iOS xcode
Related
How can I trigger the following behavior in Swift UI Tests via XCTest:
Get the app to foreground and inactive (applicationWillResignActive) and back to "foreground and active" (applicationDidBecomeActive)
Possible gestures, while app is in foreground and active, could be:
open app switcher and go back to app
open control center and hide control center
open notification center and hide notification center
I searched for something like that following fictive(!) code XCUIDevice.shared.doublePress(XCUIDevice.Button.home) or XCUIDevice.shared.swipeDownFromOutside(); XCUIDevice.shared.swipeUpFromOutside().
Or a more better way a method call to simulate an open app switcher, control center or notification center immediately.
Or in the best way to simulate the status applicationWillResignActive, applicationDidBecomeActive immediately.
Important to understand: the event applicationDidEnterBackground must not called - the app has to stay in foreground (but inactive)!
So recently on wwdc2017 Apple released a convenient way to work with multi app. You can see the multi App portion of the video link below.
https://developer.apple.com/videos/play/wwdc2017/409/
When I open the app it fires the events viewDidLoad and viewDidAppear form my View Controller but when I close it and run it again it does not call any of them.
Any idea?
You need to read up on application states. Here is a link I found online outlining the different states:
http://www.techrepublic.com/blog/software-engineer/understand-the-states-and-transitions-of-an-ios-app/
What you really want is to be notified when your app becomes active.
Probably the easiest way is to implement the function applicationDidBecomeActive() in your app delegate. That will be called when your app becomes active as the foreground app either on launch, or when it returns to the foreground as the active app.
Note that if you want that notification sent to some object other than the app delegate you can listen for the UIApplicationDidBecomeActive notification.
Suppose App is in foreground and user does not interact with app for 5 min, App should give alert.
Suppose App is in background and it remain in background for more than 5 min App should give alert as soon as app comes in foreground.
Is there any standard way to do that?
For the background part, basically you want to have a Counter. This Counter should do
Observe UIApplicationWillResignActiveNotification notification. And record the time when the selector is called. Let's say it's lastActiveTime.
Observe UIApplicationDidBecomeActiveNotification notification. And inside the selector, compare the current time with lastActiveTime. If it's more than 5 minutes, you'll pop up the alert.
For foreground, you could use some assumptions such as if the top most view controller is the same, assume the user hasn't interacted with the app. You can have a timer that keep checking the top most view controller.
How can I be notified when the iOS Control Center is being opened?
UIApplicationWillResignActiveNotification isn't good enough since this notification is sent also when the Notifications Center is opened, alert view appeared and other possible scenarios.
I was sure this is not possible, but QuizUp app is notified when the user open the Control Center while the user is on middle of a gameplay to prevent cheating the game.
Thanks
Hey there I did a lot of trial and error investigation and came up with a solution that turns out being very reliable. It works in all orientations and both in fullscreen (no statusbar) and in regular mode. AAWindow is a subclass of UIWindow and you can find it on GitHub.
The way I accomplished this is by overriding sendEvent in UIWindow, separating out TouchEvents from the other events and checking whether touches occur in the bottom 10 percent of the screen (which is the part that can open Control Center). If there are touches and applicationWillResignActive is called within a timespan of .5 seconds (with statusbar) or 3 seconds (without statusbar) you can be very sure that this is because of Control Center being opened. Then a NSNotification is being fired and you can react to that anywhere in the application.
I tested a UIPanGestureRecognizer approach (with and without the status bar visible—changes if the little pull tab comes up instead of control center) along with watching for the applicationWillResignActive notification, and I couldn't reliably know if control center was opened. If the pan was slow enough the gesture recognizer would trigger first, but it's definitely easy to swipe up fast enough to trigger control center and bypass the gesture recognizer firing at all.
Attempting to check if the app goes from applicationWillResignActive and then to applicationDidBecomeActive would be a pretty reliable way to know if the app entered and exited one of a couple states (control center, notification center, answering a phone call, etc), but telling the difference between say notification and control center is impossible this way.
TL;DR: I don't think there is a reliable or accurate way to tell if control center was opened, but QuizUp may be doing something interesting to fake it, and I am open to being wrong!
When Control centre is opened the cycle isn't completed. Means only the method
applicationDidResignActivity will be called but applicationDidEnterBackground won't be called. When app is minimized both methods will be called. Here you can differentiate.
My app checks the GPS while my app is not the active app and I use AVAudioplayer too in background.
It works fine and stays in the background doing its thing, but ios7 displays this red top banner with my app name flashing on it when it is not the active app.
How can I disable this banner, it is annoying to use other apps that are squished down 1 line?
I know this can be done as I have other GPS based background apps that don't display this flashing banner.
EDIT - So we found the answer quickly but the solution evades me:
If I stop OpenEars pocketsphinxController from listening with a button that calls this method while the program is active, the banner disappears when the app loses focus:
-(void) mystopListening{
NSLog(#"Tried to stop listening");
[pocketsphinxController stopListening];
}
BUT if I call the same method from my app delegate with (I had to import my view controller.h file in my app delegate.h and add -(void) nystopListening; in my view controller.h to make the below execute properly):
- (void)applicationWillResignActive:(UIApplication *)application{
myViewController * vc = [[myViewController alloc]init];
[vc mystopListening];
}
The banner persists! It is a little like ios7 has decided I am a recording culprit before I even have a chance to turn it off. OR, am I even turning it off?
How do I do this effectively and in what event?
EDIT - So it turns out I am not really turning pocketsphinxController off when 'mystopListening' is called from the app delegate. I know this because it DOES log the 'Tried to stop listening' when called from app delegate but the pocketsphinxController does not respond with its 'pocketsphinxDidStopListening' method. PocketsphinxController does call its 'pocketsphinxDidStopListening' method when I call 'mystopListening' from a button while the app is active.
Why won't the pocketsphinxController respond when called from from the app delegate, I must be doing it wrong?
Thanks,Carmen
Turns out I was not really calling the original pockectsphinxcontroller instance from my app delegate.
As a workaround to the problem I did this:
My app always has a timer running, so in my app delegate where I get notice of when app goes to inactive and comes back active, I just set global flags so my timer can know app active status. Then my timer just uses pockecsphinxcontroller methods to stop and start listening and voila, the banner is no more while app not active.