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

安装react-native-immediate-phone-call后React Native iOS构建失败求助

解决react-native-immediate-phone-call在M1 Mac iOS构建失败的思路

1. 验证包版本兼容性

react-native-immediate-phone-call 2.0.0发布时间较早,可能未适配RN 0.71.4:

  • 尝试降级包至1.1.0版本,或查看是否有更新的适配版本;
  • 若包已停止维护,考虑替换为react-native-phone-call等活跃维护的替代包。

2. 调整M1架构编译配置

针对M1模拟器的arm64编译冲突,修改Podfile配置:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'RNImmediatePhoneCall'
      target.build_configurations.each do |config|
        # 强制模拟器使用x86_64架构编译
        config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
      end
    end
  end
end

执行以下命令重新安装依赖:

cd ios && rm -rf Pods Podfile.lock
pod install --repo-update

3. 清理构建缓存

彻底清理缓存后重新构建:

# 删除Xcode派生数据
rm -rf ~/Library/Developer/Xcode/DerivedData
# 清理项目缓存
cd ios && xcodebuild clean
# 重新安装JS和iOS依赖
rm -rf node_modules package-lock.json
npm install
cd ios && pod install

4. 修复原生代码兼容性

报错源于RNImmediatePhoneCall.m编译失败,手动修改文件适配RN 0.71:

  • 打开node_modules/react-native-immediate-phone-call/ios/RNImmediatePhoneCall/RNImmediatePhoneCall.m;
  • 将旧版导入路径#import "RCTBridgeModule.h"替换为#import <React/RCTBridgeModule.h>;
  • 检查并替换所有过时的RN API(如RCTLog替换为RCTLogInfo);
  • 确保模块注册使用标准写法RCT_EXPORT_MODULE()。

5. 自定义原生模块替代

若以上方案无效,直接编写极简原生模块实现打电话功能:

  1. 在iOS项目中创建新的Objective-C文件RNPhoneCallModule.m;
  2. 实现基础的打电话逻辑:
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>

@interface RNPhoneCallModule : NSObject <RCTBridgeModule>
@end

@implementation RNPhoneCallModule

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(call:(NSString *)phoneNumber) {
  NSString *urlString = [NSString stringWithFormat:@"tel://%@", phoneNumber];
  NSURL *url = [NSURL URLWithString:urlString];
  if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  }
}

@end
  1. 在React Native中导入并使用:
import { NativeModules } from 'react-native';
const { RNPhoneCallModule } = NativeModules;

// 调用打电话功能
RNPhoneCallModule.call('1234567890');

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 18:07:04