修复了异常的toast

This commit is contained in:
fengshuo
2022-11-10 12:11:25 +08:00
parent ef51ef81fa
commit 4f3c21152f
2 changed files with 9 additions and 5 deletions

View File

@@ -86,7 +86,7 @@ UIKIT_EXTERN NSString * adImageName;
#ifdef DEBUG #ifdef DEBUG
config.debugMode = YES; // debug config.debugMode = YES; // debug
config.reportLogLevel = BuglyLogLevelVerbose; // config.reportLogLevel = BuglyLogLevelWarn; //
[Bugly startWithAppId:KeyWithType(KeyTyoe_BuglyKey) config:config]; [Bugly startWithAppId:KeyWithType(KeyTyoe_BuglyKey) config:config];
#else #else
config.debugMode = NO; // release config.debugMode = NO; // release

View File

@@ -21,7 +21,6 @@
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
manager = [[AFHTTPSessionManager manager]initWithBaseURL:[NSURL URLWithString:API_HOST_URL]]; manager = [[AFHTTPSessionManager manager]initWithBaseURL:[NSURL URLWithString:API_HOST_URL]];
manager.requestSerializer.timeoutInterval = 15;
manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer.HTTPShouldHandleCookies = YES; manager.requestSerializer.HTTPShouldHandleCookies = YES;
// //
@@ -31,6 +30,7 @@
// //
[manager.securityPolicy setValidatesDomainName:NO]; [manager.securityPolicy setValidatesDomainName:NO];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain",@"image/jpeg",@"image/png", nil]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain",@"image/jpeg",@"image/png", nil];
manager.requestSerializer.timeoutInterval = 40;
}); });
return manager; return manager;
} }
@@ -43,6 +43,8 @@
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) { if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
failure(-1, @"请检查网络连接。"); failure(-1, @"请检查网络连接。");
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
}); });
return; return;
} }
@@ -73,6 +75,8 @@
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) { if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
failure(-1, @"请检查网络连接。"); failure(-1, @"请检查网络连接。");
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
}); });
return; return;
} }
@@ -122,8 +126,6 @@
NSLog(@"\n%@", [baseModel toJSONString]); NSLog(@"\n%@", [baseModel toJSONString]);
#endif #endif
success(baseModel); success(baseModel);
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self handleNetError:error method:method failure:failure]; [self handleNetError:error method:method failure:failure];
}]; }];
@@ -219,6 +221,8 @@
} else { } else {
if (error.code == -1009) { if (error.code == -1009) {
failure(error.code, @"网络异常,请检查网络后重试。"); failure(error.code, @"网络异常,请检查网络后重试。");
} else if (error.code == -1001) {
failure(error.code, @"请求超时,请稍后再试。");
} else { } else {
failure(error.code, @"服务器正忙,请稍后重试。"); failure(error.code, @"服务器正忙,请稍后重试。");
} }