迁移仓库

This commit is contained in:
2026-02-24 09:55:08 +08:00
parent 2d5c056b82
commit df6210aaf7
30 changed files with 1121 additions and 81 deletions

View File

@@ -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