mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 16:22:39 +00:00
Console: BugFix SYIOS-80 - Errors when internet connection unavailable are way too intrusive.
This commit is contained in:
parent
9b91742ed9
commit
7a320bd262
2 changed files with 39 additions and 1 deletions
|
@ -32,6 +32,7 @@
|
||||||
@property (strong, nonatomic) NSString *build;
|
@property (strong, nonatomic) NSString *build;
|
||||||
|
|
||||||
@property (nonatomic) BOOL isAppForeground;
|
@property (nonatomic) BOOL isAppForeground;
|
||||||
|
@property (nonatomic) BOOL isOffline;
|
||||||
|
|
||||||
+ (AppDelegate*)theDelegate;
|
+ (AppDelegate*)theDelegate;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,10 @@
|
||||||
#define MAKE_STRING(x) #x
|
#define MAKE_STRING(x) #x
|
||||||
#define MAKE_NS_STRING(x) @MAKE_STRING(x)
|
#define MAKE_NS_STRING(x) @MAKE_STRING(x)
|
||||||
|
|
||||||
@interface AppDelegate () <UISplitViewControllerDelegate>
|
@interface AppDelegate () <UISplitViewControllerDelegate> {
|
||||||
|
// Reachability observer
|
||||||
|
id reachabilityObserver;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -72,6 +75,29 @@
|
||||||
return _build;
|
return _build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setIsOffline:(BOOL)isOffline {
|
||||||
|
if (isOffline) {
|
||||||
|
// Add observer to leave this state automatically.
|
||||||
|
reachabilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingReachabilityDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
|
||||||
|
NSNumber *statusItem = note.userInfo[AFNetworkingReachabilityNotificationStatusItem];
|
||||||
|
if (statusItem) {
|
||||||
|
AFNetworkReachabilityStatus reachabilityStatus = statusItem.integerValue;
|
||||||
|
if (reachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi || reachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||||
|
self.isOffline = NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
} else {
|
||||||
|
// Release potential observer
|
||||||
|
if (reachabilityObserver) {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:reachabilityObserver];
|
||||||
|
reachabilityObserver = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_isOffline = isOffline;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - UIApplicationDelegate
|
#pragma mark - UIApplicationDelegate
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
|
@ -144,6 +170,7 @@
|
||||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||||
|
|
||||||
// Stop reachability monitoring
|
// Stop reachability monitoring
|
||||||
|
self.isOffline = NO;
|
||||||
[[AFNetworkReachabilityManager sharedManager] stopMonitoring];
|
[[AFNetworkReachabilityManager sharedManager] stopMonitoring];
|
||||||
|
|
||||||
// check if some media msut be released to reduce the cache size
|
// check if some media msut be released to reduce the cache size
|
||||||
|
@ -257,6 +284,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (MXCAlert*)showErrorAsAlert:(NSError*)error {
|
- (MXCAlert*)showErrorAsAlert:(NSError*)error {
|
||||||
|
// Ignore network reachability error when the app is already offline
|
||||||
|
if (self.isOffline && [error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorNotConnectedToInternet) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
if (self.errorNotification) {
|
if (self.errorNotification) {
|
||||||
[self.errorNotification dismiss:NO];
|
[self.errorNotification dismiss:NO];
|
||||||
}
|
}
|
||||||
|
@ -274,6 +306,11 @@
|
||||||
}];
|
}];
|
||||||
[self.errorNotification showInViewController:[self.masterTabBarController selectedViewController]];
|
[self.errorNotification showInViewController:[self.masterTabBarController selectedViewController]];
|
||||||
|
|
||||||
|
// Switch in offline mode in case of network reachability error
|
||||||
|
if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorNotConnectedToInternet) {
|
||||||
|
self.isOffline = YES;
|
||||||
|
}
|
||||||
|
|
||||||
return self.errorNotification;
|
return self.errorNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue