我使用以下命令启动了一个新的反应本机应用程序:
react-native init myApplication
我从启动画面开始,所以我使用了这个库反应本机启动画面
我使用以下命令链接该库以生成本机代码:
react-native link react-native-splash-screen
我使用 Xcode 添加了文件,如下所示:
- 在 XCode 的项目导航器中,右键单击“库”➜ 将文件添加到 [您的项目名称]
- 转到node_modules➜react-native-splash-screen并添加SplashScreen.xcodeproj
- 在 XCode 的项目导航器中,选择您的项目。将 libSplashScreen.a 添加到项目的构建阶段 ➜ 将二进制文件与库链接
- 要修复找不到“RNSplashScreen.h”文件的问题,您必须选择项目→构建设置→搜索路径→要添加的标题搜索路径:$(SRCROOT)/../node_modules/react-native-splash-screen/ios
我在真正的 Iphone 中使用 Xcode 构建应用程序,并在 RNSplashScreen.h 中收到此错误:
/**
* SplashScreen
* 启动屏
* from:http://www.devio.org
* Author:CrazyCodeBoy
* GitHub:https://github.com/crazycodeboy
* Email:[email protected]
*/
#import <React/RCTBridgeModule.h> // <------'React/RCTBridgeModule.h' file not found
#import <UIKit/UIKit.h>
@interface RNSplashScreen : NSObject<RCTBridgeModule>
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView;
+ (void)show;
+ (void)hide;
@end
找不到“React/RCTBridgeModule.h”文件
Podfile:
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
...... # other libaries
pod 'react-native-splash-screen', :path => '../node_modules/react-
native-splash-screen'
AppDelegate.m:
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
.... <------- other code
[RNSplashScreen show];
return YES;
}