无网络提示框

This commit is contained in:
chenshuanglin
2023-03-22 17:46:43 +08:00
parent 56e60922d1
commit 18d2d9c2fc

View File

@@ -12,9 +12,13 @@
#import "YYReachability.h"
#import <AFNetworking.h>
#import <Bugly/Bugly.h>
#import "TTAlertView.h"
#import "XCCurrentVCStackManager.h"
@implementation HttpRequestHelper
static BOOL isShowing = NO;
+(AFHTTPSessionManager *)requestManager
{
static AFHTTPSessionManager *manager = nil;
@@ -35,6 +39,26 @@
return manager;
}
+ (void)showNoNetAlert {
if (isShowing == NO) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请检查网络配置或确定设备是否联网" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
isShowing = NO;
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
isShowing = NO;
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:nil completionHandler:^(BOOL success) {
}];
}
}]];
[[XCCurrentVCStackManager shareManager].getCurrentVC presentViewController:alert animated:YES completion:nil];
isShowing = YES;
}
}
+ (void)GET:(NSString *)method
params:(NSDictionary *)params
success:(void (^)(BaseModel *data))success
@@ -42,9 +66,11 @@
{
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self showNoNetAlert];
failure(-1, @"请检查网络连接。");
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
});
return;
}