解决cocos 2dx/creator2.4在ios18下openURL无法调用的问题

由于ios18废弃了旧的openURL接口,我们需要修改CCApplication-ios.mm文件的Application::openURL方法:

objectivec 复制代码
//修复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 URL
        if ([[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;
}
相关推荐
pe7er3 天前
macOS 应用无法打开(权限问题)解决方案
macos·mac
harmful_sheep6 天前
mac生效的终端查看
macos
iOS门童7 天前
macOS 应用"已损坏"无法打开?一文搞懂 Gatekeeper 与解决方案
macos
NPE~7 天前
[工具分享]Maccy —— 优雅的 macOS 剪贴板历史管理工具
macos·教程·工具·实用工具
差不多程序员7 天前
Mac安装OpenClaw-cn保姆级教程
macos
dzl843947 天前
mac 安装python
开发语言·python·macos
Bruce_Liuxiaowei7 天前
在 macOS 上通过 Docker 本地安装 OpenClaw 完整教程
macos·docker·容器·openclaw
阿捏利7 天前
详解Mach-O(十五)Mach-O __DATA_CONST
macos·ios·c/c++·mach-o
ShikiSuen7 天前
macOS 的 CpLk 中英切换卡顿的元凶在 InputMethodKit 本身
macos
xiayutian_c7 天前
如虎添翼-MacOS
macos