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

构建WebDriverAgentRunner时遇UIUserNotification相关API废弃报错求助

解决WebDriverAgentRunner构建时UIUserNotification相关API废弃报错

核心修改思路

UIUserNotificationTypeAlert、UIUserNotificationSettings、registerUserNotificationSettings:是iOS 10起被废弃的API,需替换为UserNotifications框架的新接口,具体修改步骤如下:

1. 定位目标代码文件

在WebDriverAgent项目中,找到使用上述废弃API的文件(通常为FBApplicationCommands.m或FBSettingsCommands.m)。

2. 导入新框架头文件

在文件顶部添加:

#import <UserNotifications/UserNotifications.h>

3. 替换废弃枚举与代码逻辑

  • 将UIUserNotificationTypeAlert替换为UNAuthorizationOptionAlert(若需同时启用声音、徽章权限,可组合为UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
  • 替换原通知注册代码:

原废弃代码示例:

UIUserNotificationType types = UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[application registerUserNotificationSettings:settings];

替换为iOS 10+兼容的新代码:

UNAuthorizationOptions options = UNAuthorizationOptionAlert;
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {
    // 按需处理权限请求结果
}];
// 可选:立即获取当前通知设置状态
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
    // 按需处理设置结果
}];

4. 兼容低版本iOS(可选)

若需支持iOS 10以下系统,添加版本判断:

if (@available(iOS 10.0, *)) {
    UNAuthorizationOptions options = UNAuthorizationOptionAlert;
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {}];
} else {
    UIUserNotificationType types = UIUserNotificationTypeAlert;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [application registerUserNotificationSettings:settings];
}

5. 重新构建项目

清理Xcode缓存(Cmd+Shift+K),然后重新构建WebDriverAgentRunner。


内容的提问来源于stack exchange,提问作者Oguzhan K

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 10:30:48