无法在iOS上运行react-native-unimodules

问题描述

我正在运行一个裸露的RN项目,并且我想使用expo-local-authentication,因此必须安装react-native-unimodules。

我在Android上运行它,但在iOS上却无法运行。当我尝试console.log(Constants)时,我得到一个对象,其中所有值均为null或未定义(它在Android上为我提供了正确的值)

{appOwnership: null,manifest: null,deviceid: undefined,linkingUrl: undefined}

我尝试按照此处PEP 492

列出的步骤进行操作

我尝试运行npx pod-installnpm run ios --reset-cache并从xcode清除构建缓存。似乎没有任何效果,希望您能对我有所帮助。

我正在与: RN:0.63.2 unimodules:0.11.0

在完成安装指南中显示修改后,这是iOS文件的外观: AppDelegate.h

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>

#import <UMCore/UMAppDelegateWrapper.h>
 
@interface AppDelegate : UMAppDelegateWrapper <UIApplicationDelegate,RCTBridgeDelegate>

@property (nonatomic,strong) UIWindow *window;

@end

AppDelegate.m

#import "AppDelegate.h"

#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
 

#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>



static void Initializeflipper(UIApplication *application) {
  FlipperClient *client = [FlipperClient sharedClient];
  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
  [client addplugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
  [client addplugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addplugin:[FlipperKitReactPlugin new]];
  [client addplugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
}
#endif

@interface AppDelegate () <RCTBridgeDelegate>
 
@property (nonatomic,strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
 
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }
#if DEBUG
  Initializeflipper(application);
#endif

  self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"___APP_NAME___"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  [super application:application didFinishLaunchingWithOptions:launchOptions];

  if (@available(iOS 14,*)) {
    UIDatePicker *picker = [UIDatePicker appearance];
    picker.preferredDatePickerStyle = UIDatePickerStyleWheels;
  }
 


  return YES;
}

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
    NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
    // If you'd like to export some custom RCTBridgeModules that are not Expo modules,add them here!
    return extraModules;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

Podfile

platform :ios,'14.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'

def add_flipper_pods!(versions = {})
  versions['Flipper'] ||= '~> 0.33.1'
  versions['DoubleConversion'] ||= '1.1.7'
  versions['Flipper-Folly'] ||= '~> 2.1'
  versions['Flipper-Glog'] ||= '0.3.6'
  versions['Flipper-PeerTalk'] ||= '~> 0.0.4'
  versions['Flipper-RSocket'] ||= '~> 1.0'

  pod 'FlipperKit',versions['Flipper'],:configuration => 'Debug'
  pod 'FlipperKit/FlipperKitLayoutPlugin',:configuration => 'Debug'
  pod 'FlipperKit/SKIOSNetworkPlugin',:configuration => 'Debug'
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin',:configuration => 'Debug'
  pod 'FlipperKit/FlipperKitReactPlugin',:configuration => 'Debug'

  # List all transitive dependencies for FlipperKit pods
  # to avoid them being linked in Release builds
  pod 'Flipper',:configuration => 'Debug'
  pod 'Flipper-DoubleConversion',versions['DoubleConversion'],:configuration => 'Debug'
  pod 'Flipper-Folly',versions['Flipper-Folly'],:configuration => 'Debug'
  pod 'Flipper-Glog',versions['Flipper-Glog'],:configuration => 'Debug'
  pod 'Flipper-PeerTalk',versions['Flipper-PeerTalk'],:configuration => 'Debug'
  pod 'Flipper-RSocket',versions['Flipper-RSocket'],:configuration => 'Debug'
  pod 'FlipperKit/Core',:configuration => 'Debug'
  pod 'FlipperKit/CppBridge',:configuration => 'Debug'
  pod 'FlipperKit/FBCxxFollyDynamicConvert',:configuration => 'Debug'
  pod 'FlipperKit/FBDefines',:configuration => 'Debug'
  pod 'FlipperKit/FKPortForwarding',:configuration => 'Debug'
  pod 'FlipperKit/FlipperKitHighlightOverlay',:configuration => 'Debug'
  pod 'FlipperKit/FlipperKitLayoutTextSearchable',:configuration => 'Debug'
  pod 'FlipperKit/FlipperKitNetworkPlugin',:configuration => 'Debug'
end

# Post Install processing for Flipper
def flipper_post_install(installer)
  installer.pods_project.targets.each do |target|
    if target.name == 'YogaKit'
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '4.1'
      end
    end
  end
end

target '__APP_NAME__' do
  
  # Pods for __APP_NAME__
  pod 'FblazyVector',:path => "../node_modules/react-native/Libraries/FblazyVector"
  pod 'FBReactNativeSpec',:path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTrequired',:path => "../node_modules/react-native/Libraries/RCTrequired"
  pod 'RCTTypeSafety',:path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React',:path => '../node_modules/react-native/'
  pod 'React-Core',:path => '../node_modules/react-native/'
  pod 'React-CoreModules',:path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport',:path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet',:path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation',:path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob',:path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCtimage',:path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking',:path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork',:path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings',:path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText',:path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration',:path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket',:path => '../node_modules/react-native/'

  pod 'React-cxxreact',:path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi',:path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor',:path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector',:path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'React-callinvoker',:path => "../node_modules/react-native/ReactCommon/callinvoker"
  pod 'ReactCommon/turbomodule/core',:path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga',:path => '../node_modules/react-native/ReactCommon/yoga',:modular_headers => true

  pod 'DoubleConversion',:podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog',:podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly',:podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'


  target '__APP_NAME__Tests' do
    inherit! :complete
    # Pods for testing
  end


  use_native_modules!
  use_unimodules!

  


  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled,Flipper will not work and
  # you should disable these next few lines.
  add_flipper_pods!
  post_install do |installer|
    flipper_post_install(installer)
  end
end

target '__APP_NAME__-tvOS' do
  # Pods for __APP_NAME__-tvOS

  target '__APP_NAME__-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

如果有任何其他有用的信息,请随时提出要求

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)