-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When starting the app in airplane mode, the listener is not notified #2677
Comments
Hi @alekop, Thank you for the report. Could you report which device and version of iOS you are running? Also, could you try the following code and see if it behaves better? let reachability = ReachabilityNetworkManager()!
reachability.listener = { print("isReachable: \($0)") }
reachability.startListening()
If you could report back on your findings I'd greatly appreciate it. |
Hi @cnoon, I tried the no-hostname initializer, but it didn't make any difference. The issue seems to be here, in NetworkReachabilityManager.swift:
Both
|
What versions of iOS have you tried this on @alekop? I'm guessing this is a change in functionality somewhere along the line. |
I tried 11.4.1, 12, 12.1. |
Cool. Thank you for all the info here! My guess for now is that the behavior here changed somewhere along the lines under-the-hood because I'm positive this used to work on older versions. I'll do some investigation and get a fix put together. Just FYI, I'll be out on PTO for the rest of the week so I really doubt I'll be able to get a patch put together until I get back. If this is super pressing, I'd suggest making the fix you suggested and give it a whirl in a fork. If you're confident in the change, I'd also recommend putting together a PR.
|
Prior to this change, the reachability listener was notified at launch if the device was not in airplane mode. When in airplane mode, the reachability flags were 0, which is what we were defaulting the previous flags to. Because of this, the notifyListener function would early out since the flags had not changed. The core issue here was that the default value of previousFlags was poorly chosen. It should instead default to a value that represents and unknown status. One way to do this would be to make previousFlags an optional. However, this change would not be backwards compatible, so it was abandoned. The best backwards compatible way to make this change was to set previousFlags to a rawValue that is not currently used. That way, we can guarantee that the originally computed flags will be different than the default previous flags. This change results in the listener being called at launch even when in airplane mode. Please refer to issue #2677 for more details.
Okay @alekop, I just pushed up #2688 to resolve the issue you are seeing. Your breakdown of the issue was spot on and I modified the original value of I'm going to go ahead and close this issue out. Let's continue this conversation in #2688. Cheers. 🍻 |
I'm positive this used to work. Thank you for reporting this @alekop. |
Prior to this change, the reachability listener was notified at launch if the device was not in airplane mode. When in airplane mode, the reachability flags were 0, which is what we were defaulting the previous flags to. Because of this, the notifyListener function would early out since the flags had not changed. The core issue here was that the default value of previousFlags was poorly chosen. It should instead default to a value that represents and unknown status. One way to do this would be to make previousFlags an optional. However, this change would not be backwards compatible, so it was abandoned. The best backwards compatible way to make this change was to set previousFlags to a rawValue that is not currently used. That way, we can guarantee that the originally computed flags will be different than the default previous flags. This change results in the listener being called at launch even when in airplane mode. Please refer to issue #2677 for more details.
Hello! Problem is still here. I run my app from Xcode via wire on the device with turned on airplane mode and NetworkReachabilityManager()?.isReachable returns "reachable" merely once.
|
What did you do?
What did you expect to happen?
The
print
statement should have printed "isReachable: false"What happened instead?
Nothing is printed when starting with no connectivity. But if you start the app with connectivity, it will print. The initial notification is not called in airplane mode.
The issue is that
flags
andpreviousFlags
both have a rawValue of 0, so the guard in notifyListener returns. The previous flags should probably default unknown, rather than 0, which means not-reachable.Alamofire Environment
Alamofire version: 4.8.0
Xcode version: 10.1
Swift version: 4.2
Platform(s) running Alamofire: iOS
macOS version running Xcode: 10.13.6
The text was updated successfully, but these errors were encountered: