iOS 问题收集及处理 (弃用方法收集)持续更新中(warning,errors)

本文汇总了iOS开发中常见的警告与错误信息,包括弃用API如UIAlertView、ABPeoplePickerNavigationController等的替代方案,以及真机调试时遇到的问题如launchscreen黑屏的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 1.warning
  • 2.errors
  • 3.真机运行

warning:(报黄⚠️)

1.CGSize sz = [message sizeWithFont:ft constrainedToSize:CGSizeMake(250, 1000)];

2.NSArray*ifs = (__bridgeid)CNCopySupportedInterfaces();
id info = nil;

for (NSString *ifnam in ifs) {

    info = (__bridge id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);

    if (info && [info count]) {

        break;

    }

}
3.constrainedToSize

CGSize sz = [message sizeWithFont:ft constrainedToSize:CGSizeMake(250, 1000)];
alertView 弃用 (UIAlertController 代替)

4. ABPeoplePickerNavigationController iOS 9.0之后弃用

这里写图片描述

代替方案:
引用—–>

#import <ContactsUI/CNContactViewController.h>
#import <ContactsUI/CNContactPickerViewController.h>

这里写图片描述

5.stringByAddingPercentEscapesUsingEncoding iOS9.0后弃用
NSString *str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

这里写图片描述

解决方案:

    NSString *string = @"hahahaha";
    NSString *Urlstring = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLUserAllowedCharacterSet]];

这里写图片描述

6.UIAlertView (iOS9.0后弃用)
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];

同时弃用的还有 UIActionSheet (iOS 8.3 后弃用)

 UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"收款" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"保存", nil];
    actionSheet.tag = 105;
    [actionSheet showInView:self.view];

这里写图片描述

7.interfaceOrientation (iOS8.0后弃用)
    UIInterfaceOrientation toInterfaceOrientation = self.interfaceOrientation;

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
        [self remasMakeForVertical];
    }else{
        [self remasMakeForLandscape];

    }

这里写图片描述

8.applicationFrame(iOS 9.0 后弃用)
screenshotImgView.frame = [UIScreen mainScreen].applicationFrame;

这里写图片描述

————–分割————–

errors:(报红)

真机调试问题

1.launchscreen 黑屏问题

可能原因: 真机运行内存较小,launchscreen图片过大
解决方法: 删除掉原先的launch screen 重新建立一个launchscreen.storyBoard (iOS 8.0以下 位launchscreen.xib) 重新建立后运行成功.
希望有哪位大神可以解释下原因.

ERROR: Failed :entry:default@BuildNativeWithCmake... > hvigor ERROR: Exceptions happened while executing: Not searching for unused variables given on the command line. CMake Warning (dev) at CMakeLists.txt:1 (project): cmake_minimum_required() should be called prior to this top-level project() call. Please see the cmake-commands(7) manual for usage documentation of both commands. This warning is for project developers. Use -Wno-dev to suppress it. CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at E:/MyApplicationRn/entry/oh_modules/@rnoh/react-native-openharmony/src/main/cpp/CMakeLists.txt:6 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at E:/MyApplicationRn/entry/oh_modules/@rnoh/react-native-openharmony/src/main/cpp/third-party/boost/libs/predef/CMakeLists.txt:23 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- Boost.Context: architecture arm64, binary format elf, ABI aapcs, assembler gas, suffix .S, implementation fcontext Experimental C-API architecture enabled CMake Error at CMakeLists.txt:23 (add_subdirectory): The binary directory E:/MyApplicationRn/entry/.cxx/default/default/debug/arm64-v8a/permissions is already used to build a source directory. It cannot be used to build source directory E:/MyApplicationRn/entry/oh_modules/@react-native-oh-tpl/react-native-permissions/src/main/cpp Specify a unique binary directory name. -- Configuring incomplete, errors occurred!鸿蒙项目运行报错
最新发布
08-15
<think>我们遇到了一个CMake构建错误,错误信息显示在`add_subdirectory`命令中出现了问题:尝试在同一个二进制目录下构建两个不同的源目录。具体来说,错误信息如下: ``` CMake Error at CMakeLists.txt:23 (add_subdirectory): The binary directory E:/MyApplicationRn/entry/.cxx/default/default/debug/arm64-v8a/permissions is already used to build a source directory. It cannot be used to build source directory E:/MyApplicationRn/entry/oh_modules/@react-native-oh-tpl/react-native-permissions/src/main/cpp Specify a unique binary directory name. ``` 这个错误通常发生在CMake项目中,当两个不同的子项目(通过`add_subdirectory`添加)试图使用同一个二进制输出目录时。在React Native项目中,这可能是由于两个不同的native模块(或同一个模块的不同部分)被配置为使用相同的构建路径。 ### 解决方案 我们需要修改`react-native-permissions`模块的CMake配置,使其使用一个唯一的二进制目录。可以通过在`add_subdirectory`命令中指定一个二进制目录参数来实现。 #### 步骤: 1. **找到调用`add_subdirectory`的地方**: 根据错误信息,问题出现在项目的`CMakeLists.txt`文件的第23行,该行尝试添加`@react-native-oh-tpl/react-native-permissions`模块的CMake子目录。 2. **修改CMakeLists.txt**: 在`add_subdirectory`命令中,我们可以显式指定一个二进制目录,以避免冲突。 将: ```cmake add_subdirectory(${REACT_NATIVE_PERMISSIONS_DIR}/src/main/cpp permissions) ``` 修改为(注意:这里我们修改了二进制目录名称,添加一个唯一标识,比如模块名): ```cmake add_subdirectory(${REACT_NATIVE_PERMISSIONS_DIR}/src/main/cpp react-native-permissions) ``` 或者,如果已经指定了第二个参数(二进制目录),那么修改这个参数使其唯一。 3. **如果问题仍然存在**: 可能是其他模块也使用了相同的二进制目录名。我们需要确保每个`add_subdirectory`调用的第二个参数(二进制目录名)都是唯一的。 ### 实际代码修改 假设我们项目的`CMakeLists.txt`文件位于`entry`目录下,我们需要修改该文件。以下是修改示例: ```cmake # 在CMakeLists.txt中找到添加react-native-permissions的地方 # 原始可能是: # add_subdirectory(${REACT_NATIVE_PERMISSIONS_DIR}/src/main/cpp permissions) # 修改为(使用一个更具体的目录名): add_subdirectory(${REACT_NATIVE_PERMISSIONS_DIR}/src/main/cpp react-native-permissions) ``` ### 完整修复步骤 1. 打开文件:`entry/CMakeLists.txt` 2. 找到第23行左右的`add_subdirectory`命令,该命令添加了`react-native-permissions`模块。 3. 修改该命令,确保第二个参数(二进制目录名)是唯一的。通常,我们可以使用模块名作为目录名。 ### 注意 另外,错误信息中还有关于`cmake_minimum_required`的警告。建议将`cmake_minimum_required`放在文件的最前面。例如: ```cmake # 将cmake_minimum_required放在最前面 cmake_minimum_required(VERSION 3.4.1) project(MyApplicationRn) ``` 修改后,重新构建项目。 ### 如果问题依旧 如果修改后问题仍然存在,可能是因为其他模块也使用了相同的二进制目录名。我们需要检查所有`add_subdirectory`命令,确保每个命令的二进制目录参数都是唯一的。 例如,在同一个CMakeLists.txt中,如果有多个`add_subdirectory`,那么每个的第二个参数都不能相同。 ### 示例:修改后的CMakeLists.txt片段 ```cmake cmake_minimum_required(VERSION 3.4.1) project(MyApplicationRn) # ... 其他设置 ... # 添加react-native-openharmony add_subdirectory(${REACT_NATIVE_OPENHARMONY_DIR}/src/main/cpp rnoh) # 添加react-native-permissions,使用唯一的二进制目录名 add_subdirectory(${REACT_NATIVE_PERMISSIONS_DIR}/src/main/cpp react-native-permissions) ``` ### 重新构建 修改后,重新运行构建命令。 §§相关问题§§: 1. 如何在CMake中避免多个子项目使用相同的二进制目录? 2. 在HarmonyOS中,如何正确配置React Native的CMakeLists.txt文件? 3. 如何处理CMake中的`cmake_minimum_required`警告? 4. 在React Native项目中,如何管理多个native模块的CMake依赖?</think>根据您提供的鸿蒙项目构建错误信息,问题主要出在 CMake 配置冲突上。以下是完整的解决方案: ### 问题分析 错误信息显示: 1. `cmake_minimum_required()` 应该在 `project()` 之前调用 2. 多个 CMake 版本兼容性警告 3. **关键错误**:多个模块尝试使用相同的二进制目录 `permissions` ### 完整解决方案 #### 1. 修改项目根目录的 `CMakeLists.txt` 文件 ```cmake # 文件路径: entry/CMakeLists.txt # 将 cmake_minimum_required 放在最前面 cmake_minimum_required(VERSION 3.4.1) project(MyApplicationRn) # 设置 C++ 标准 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # 添加 OpenHarmony RN 模块 add_subdirectory(${REACT_NATIVE_OPENHARMONY_DIR}/src/main/cpp rnoh) # 修改为唯一的二进制目录名 add_subdirectory( ${REACT_NATIVE_PERMISSIONS_DIR}/src/main/cpp react-native-permissions # 修改为唯一名称 ) # 添加其他依赖模块 # add_subdirectory(... unique_name) ``` #### 2. 修改权限模块的 CMake 配置 ```cmake # 文件路径: oh_modules/@react-native-oh-tpl/react-native-permissions/src/main/cpp/CMakeLists.txt cmake_minimum_required(VERSION 3.4.1) project(react-native-permissions) # 添加预编译库 add_library( react-native-permissions SHARED "react-native-permissions.cpp" ) # 包含目录 target_include_directories( react-native-permissions PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${REACT_NATIVE_OPENHARMONY_DIR}/src/main/cpp ) # 链接库 target_link_libraries( react-native-permissions reactnative rnoh ) ``` #### 3. 更新项目配置 (build.gradle) ```groovy // 文件路径: entry/build.gradle apply plugin: 'com.huawei.ohos.hap' apply plugin: 'com.huawei.ohos.decctest' ohos { compileSdkVersion 8 defaultConfig { compatibleSdkVersion 8 } buildTypes { release { proguardOpt { proguardEnabled false rulesFiles 'proguard-rules.pro' } } } externalNativeBuild { cmake { version "3.10.2" // 明确指定CMake版本 path "src/main/cpp/CMakeLists.txt" // 确保路径正确 } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(path: ':oh_modules:@rnoh:react-native-openharmony') // 确保权限模块正确引用 implementation project(path: ':oh_modules:@react-native-oh-tpl:react-native-permissions') testImplementation 'junit:junit:4.13' ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' } ``` #### 4. 清理和重建命令 ```bash # 清理项目 cd MyApplicationRn ./gradlew clean # 删除构建缓存 rm -rf entry/.cxx # 重建项目 ./gradlew build ``` ### 错误修复说明 1. **CMake 顺序问题**: - 将 `cmake_minimum_required()` 移到 `project()` 之前 - 明确指定 CMake 版本 (3.4.1) 2. **二进制目录冲突**: ```diff - add_subdirectory(... permissions) + add_subdirectory(... react-native-permissions) ``` - 为每个模块指定唯一的二进制目录名称 3. **依赖管理**: - 确保所有模块在 build.gradle 中正确声明 - 验证模块路径是否与实际目录结构匹配 4. **版本兼容性**: - 在 build.gradle 中明确指定 CMake 版本 - 更新兼容 SDK 版本 ### 常见问题排查 如果问题仍然存在,尝试以下步骤: 1. **检查模块路径**: ```bash ls -l oh_modules/@react-native-oh-tpl/react-native-permissions ``` 2. **验证 CMake 版本**: ```bash cmake --version # 确保版本 >= 3.10.2 ``` 3. **检查 gradle 配置**: ```gradle // build.gradle (项目级) dependencies { classpath 'com.huawei.ohos:hap:3.0.3.4' classpath 'com.huawei.ohos:decctest:1.2.6.0' } ``` ### 预防措施 1. **模块命名规范**: ```cmake # 为每个模块使用唯一前缀 add_subdirectory(${MODULE_PATH} rn-module-${MODULE_NAME}) ``` 2. **统一 CMake 版本**: ```cmake # 在所有 CMakeLists.txt 开头添加 cmake_minimum_required(VERSION 3.10.2) ``` 3. **定期清理缓存**: ```bash # 在 package.json 中添加脚本 "scripts": { "clean": "rm -rf android/.cxx ios/build node_modules" } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值