You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS端Branch DeepLink无法唤起App,报‘Use of undeclared identifier 'Branch'’错误

问题解决:导入Branch库后仍报「Use of undeclared identifier 'Branch'」

排查及修复方向:

  • 确认库的导入有效性
    若用CocoaPods导入,检查Podfile是否包含pod 'Branch',且执行过pod install。必须打开.xcworkspace文件而非.xcodeproj。
    若手动导入,确保Branch框架已添加到项目的「Frameworks, Libraries, and Embedded Content」中,且「Embed」选项设为「Embed & Sign」。

  • 修正头文件导入路径
    检查#import <Branch/Branch.h>是否匹配导入方式:手动导入时可能需要改为#import "Branch.h",或在项目「Build Settings」->「Header Search Paths」中添加Branch头文件目录并设为recursive。

  • 清理缓存重新构建
    执行Cmd+Shift+K清理项目,再用Cmd+B重新构建,缓存异常可能导致识别失败。

  • 验证版本兼容性
    确认Branch库版本与当前Xcode、iOS系统版本兼容,可尝试更新至最新稳定版或回退适配版本。

  • 检查Build Configuration配置
    确保当前使用的Debug/Release配置下,Branch库已被正确引入,部分场景下库可能仅在特定Configuration中添加。

代码补充验证

你的初始化代码逻辑无误,需确保在AppDelegate的didFinishLaunchingWithOptions方法中调用:

#import <Branch/Branch.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Branch setUseTestBranchKey:YES];
    [[Branch getInstance] initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandler:^(NSDictionary * _Nonnull params, NSError * _Nullable error) {
        NSLog(@"%@", params);
        // 在此添加唤起后的页面跳转逻辑
    }];
    return YES;
}

同时需在AppDelegate中补充后台唤起的处理代码:

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
    BOOL handled = [[Branch getInstance] continueUserActivity:userActivity];
    return handled;
}

内容的提问来源于stack exchange,提问作者Jyoti Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 11:10:23