迁移仓库
This commit is contained in:
@@ -34,14 +34,20 @@
|
||||
[self setupGameURLData];
|
||||
}
|
||||
|
||||
-(void)intoMainWebView
|
||||
{
|
||||
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
||||
MainOldViewController *webViewController = [sb instantiateViewControllerWithIdentifier:@"MainOldViewController"];
|
||||
webViewController.mainURLString = self.mainURLString;
|
||||
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
appDelegate.mainURLString = self.mainURLString;
|
||||
appDelegate.window.rootViewController = webViewController;
|
||||
-(void)intoMainWebView:(NSString *)backupDomains {
|
||||
//主域名不行用备用域名
|
||||
NSArray *textArr = [backupDomains componentsSeparatedByString:@","];
|
||||
[self getAccessibleDomain:self.mainURLString backupDomains:textArr completion:^(NSString *accessibleDomain) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.mainURLString = accessibleDomain;
|
||||
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
||||
MainOldViewController *webViewController = [sb instantiateViewControllerWithIdentifier:@"MainOldViewController"];
|
||||
webViewController.mainURLString = self.mainURLString;
|
||||
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||
appDelegate.mainURLString = self.mainURLString;
|
||||
appDelegate.window.rootViewController = webViewController;
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)setupGameURLData
|
||||
@@ -81,8 +87,9 @@
|
||||
|
||||
self.mainURLString = [datadic objectForKey:@"url"];
|
||||
self.mainURLString = [self.mainURLString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||
NSString *backupDomains = [datadic objectForKey:@"backupDomains"];
|
||||
if (!ISNULLSTR(self.mainURLString)) {
|
||||
[self intoMainWebView];
|
||||
[self intoMainWebView:backupDomains];
|
||||
}
|
||||
}else{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@@ -131,4 +138,84 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)checkDomainAccessibility:(NSString *)domain completion:(void(^)(BOOL isAccessible))completion {
|
||||
NSString *urlString = domain;
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
|
||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||
BOOL isAccessible = NO;
|
||||
|
||||
if (error) {
|
||||
// 请求失败
|
||||
NSLog(@"Domain %@ is not reachable: %@", domain, error.localizedDescription);
|
||||
} else {
|
||||
// 请求成功,检查返回的状态码
|
||||
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
|
||||
if (httpResponse.statusCode == 200) {
|
||||
isAccessible = YES;
|
||||
} else {
|
||||
NSLog(@"Domain %@ returned status code: %ld", domain, (long)httpResponse.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
// 回调,返回访问状态
|
||||
if (completion) {
|
||||
completion(isAccessible);
|
||||
}
|
||||
}];
|
||||
[task resume];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - 主域名不行用备用域名
|
||||
- (void)getAccessibleDomain:(NSString *)primaryDomain backupDomains:(NSArray<NSString *> *)backupDomains completion:(void(^)(NSString *accessibleDomain))completion {
|
||||
if (ISNULLARRAY(backupDomains)) {
|
||||
if (completion) {
|
||||
completion(primaryDomain);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 首先检查主域名
|
||||
[self checkDomainAccessibility:primaryDomain completion:^(BOOL isAccessible) {
|
||||
if (isAccessible) {
|
||||
// 如果主域名可访问,直接返回主域名
|
||||
if (completion) {
|
||||
completion(primaryDomain);
|
||||
}
|
||||
} else {
|
||||
// 主域名不可访问,遍历备用域名
|
||||
__block NSString *reachableDomain = nil;
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
|
||||
// 遍历备用域名进行检查
|
||||
for (NSString *backupDomain in backupDomains) {
|
||||
dispatch_group_enter(group);
|
||||
|
||||
[self checkDomainAccessibility:backupDomain completion:^(BOOL isAccessible) {
|
||||
if (isAccessible && !reachableDomain) {
|
||||
reachableDomain = backupDomain;
|
||||
}
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
}
|
||||
|
||||
// 等待所有备用域名的检查完成
|
||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||
// 如果找到了可访问的备用域名,返回它
|
||||
if (reachableDomain) {
|
||||
if (completion) {
|
||||
completion(reachableDomain);
|
||||
}
|
||||
} else {
|
||||
// 如果所有域名都不可访问,返回主域名
|
||||
if (completion) {
|
||||
completion(primaryDomain);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user