由于ios18废弃了旧的openURL接口,我们需要修改CCApplication-ios.mm文件的Application::openURL方法:
//修复openURL在ios18下无法调用的问题
bool Application::openURL(const std::string &url)
{// NSString* msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];// NSURL* nsUrl = [NSURL URLWithString:msg];// return [[UIApplication sharedApplication] openURL:nsUrl];@autoreleasepool {NSURL *nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]];// 检查是否为 HTTP/HTTPS URLif ([[nsUrl scheme] isEqualToString:@"http"] || [[nsUrl scheme] isEqualToString:@"https"]) {if (@available(iOS 14.5, *)) {NSDictionary *options = @{UIApplicationOpenExternalURLOptionsEventAttributionKey : @YES};[[UIApplication sharedApplication] openURL:nsUrl options:options completionHandler:^(BOOL success) {if (success) {// URL成功打开} else {// URL打开失败}}];return YES;}}// 其他情况使用旧方法if (@available(iOS 10.0, *)) {[[UIApplication sharedApplication] openURL:nsUrl options:@{} completionHandler:nil];} else {[[UIApplication sharedApplication] openURL:nsUrl];}return YES;}return NO;
}