Distinguish notification center hiding and returning from background with DidBecomeActive notification - ios

I'm confused about UIApplicationDidBecomeActiveNotification. I can register an observer for this notification, and receive signals when the app becomes active from the background or when being launched. However, when I pull down the hidden top popup view (for general information: notifications, weather, stock market) then pull up to hide it, the signal is also generated.
I use a callback method hooked with this signal to refresh my app, so this can be annoying for users of my app.
Can anybody help me differentiate these cases?

Maybe you should try UIApplicationWillEnterForegroundNotification, the apple doc has said:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
UIApplicationDidBecomeActiveNotification: Posted when the application becomes active.
An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.

Related

Swift iOS system notification dismiss calback

Question:
Is there a way to detect if you get a system notification and you swipe away the notification banner (e.g. the alarm that triggers a system notification)?
More practical example:
In your app, you are doing some stuff and suddenly you get a notification from another app. Instead of tapping on the notification, you swipe up the notification (you dismiss it that way). After doing that, I want to capture that in the app.
Why:
Currently, I have a bug in the app, so if I can capture this action, I would be able to fix this bug.
Thanks in advance!
When notification appears, the willResignActiveNotification won't get called, therefore willEnterForegroundNotification won't get called, too.
The best solution here is to catch incoming notification and show the custom view describing this notification instead of system one. Thus, you can detect all actions/timings you need.

Detect when a notification appears (from another application) to change my layout

Do I want to know if it's possible to detect when a notification from another application is over my app? For example, when the user receives an SMS or Messenger message. Detect the fact that a notification is present on the screen. I don't want the content of the message.
It's an example, It can be a notification for whatever. Because, when a notification is visible, my player's lost because a part of the UI is under the notification. So, if I know when a notification is visible I can change the layout.
It's not possible to handle notifications from other apps. It would be a huge privacy violation.

UI-Test with XCTest: how to trigger App-State Foreground-Inactive Foreground-Active

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/

UIApplicationState of app is inactive after following interactive push notification when app is closed

App is not running. Interactive push notification comes in. User taps a button on it. App is launched, notification action is handled, but app state is still inactive. Even when I background/foreground the app, it's still inactive. If I follow the notification directly (tapping the notification, not the interactive button) from the same notification, the app gets launched and is in active state. Why doesn't it always go to active state?
Have some thoughts on this.
First of all, it's not a given that a notification will result in a user opening up the app.
Second, there are notification callbacks in the delegate. Is it possible to manually set the application state?
If not, and I don't want to jump to conclusions, but this sounds like it may be a bug, and you may want to file a radar.
Although, you may be able to work around it. Look at those delegate methods.

detect why iOS app went into background, hardware home or incoming push notification

I want my app to behave differently if the user pushes hardware home button, versus other reasons it may go into background. I think I have sorted out the main cases, except I can't tell the difference between user tapping on incoming push notification from another app and hitting the hardware home. In iOS 5, I was getting an applicationWillResignActive when the notify first appeared, and then applicationDidEnterBackground when the user tapped. In iOS 6, I cannot find any event triggered by the appearance of a banner notification from another app. The applicationWillResignActive and applicationDidEnterBackground come back to back, just as in hitting hardware home. I tried listening to UIWindowDidBecomeVisibleNotification and other UIWindow notification, but nothing is fired. Any ideas?

Resources