Changes in AppDelegate from Objective-C to Swift in React Native 0.77 and Above
Since React Native version 0.77, the AppDelegate has been changed from Objective-C to Swift for iOS projects. This means that your import statements and setup might need to be adjusted accordingly.
Can you tell me when these changes will be applied?
π Consider Using react-native-splash-view Instead!
Hey there! π If you're facing issues with AppDelegate changes in React Native 0.76+, you might want to try [react-native-splash-view] instead!
β
Why switch to react-native-splash-view?
- Fully compatible with React Native 0.76+, including Swift-based AppDelegate.
- No extra hassleβworks smoothly with both Objective-C & Swift projects.
- Simple integration with iOS storyboard splash screens & Android launch screens.
- Lightweight & actively maintained for the latest React Native versions.
Check it out & give it a try! πβ¨
π Consider Using
react-native-splash-viewInstead!Hey there! π If you're facing issues with
AppDelegatechanges in React Native 0.76+, you might want to try[react-native-splash-view]instead!β Why switch to
react-native-splash-view?
- Fully compatible with React Native 0.76+, including Swift-based AppDelegate.
- No extra hassleβworks smoothly with both Objective-C & Swift projects.
- Simple integration with iOS storyboard splash screens & Android launch screens.
- Lightweight & actively maintained for the latest React Native versions.
Check it out & give it a try! πβ¨
how to use in old AppDelegate instead swift?
@muammadibal
please check readme for steps:
https://github.com/jagnesh/react-native-splash-view?tab=readme-ov-file#if-you-are-using-obj-c-update-appdelegatem-or-appdelegatemm
umm...I was in a hurry, so I used react-native-bootsplash.
umm...I was in a hurry, so I used react-native-bootsplash.
No worries! React Native Bootsplash is also a solid choice. π However, for future projects, Iβd recommend checking out react-native-splash-view. It supports React Native 0.76+ with the new architecture, works seamlessly with both iOS & Android, and allows more flexibility in controlling the splash screen from native & JS sides. π Give it a look for your next project! π
Edit: This Objective-C workaround was created as a temporary solution I used to quickly publish an app in production. However, it's not the recommended approach since React Native is moving toward Swift, and we'll soon be migrating from CocoaPods to SPM. The better long-term solution is Swift migration with bridging header.
π Objective-C Workaround (Click to expand)
Found a way to work around the AppDelegate.swift changes in React Native 0.77 and above.
As mentioned in the React Native 0.77 blog:
"New projects will be generated by using Swift as the iOS app language, although you can always migrate back to Objective-C if you need to."
Since react-native-splash-screen doesn't support Swift currently, migrating back to Objective-C is an option for compatibility.
Steps (using Xcode):
- Delete
AppDelegate.swift. - Recreate (refer to Upgrade Helper):
AppDelegate.hmain.mAppDelegate.mm(Also, need to integrate RCTAppDependencyProvider which is a new change required in 0.77)
Updated AppDelegate.mm
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <ReactAppDependencyProvider/RCTAppDependencyProvider.h>
#import "RNSplashScreen.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"RnDiffApp";
self.dependencyProvider = [RCTAppDependencyProvider new];
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
bool didLaunchFinish = [super application:application didFinishLaunchingWithOptions:launchOptions];
[RNSplashScreen show];
return didLaunchFinish;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
return [self bundleURL];
}
- (NSURL *)bundleURL
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end
Note: Use Xcode to delete/recreate files so that project.pbxproj updates correctly. π
β οΈ: Not recommended. This is a temporary workaround that goes against React Native's Swift direction and upcoming SPM migration. Use Swift with bridging headers instead for future compatibility.
What worked for me was using a bridging header while doing the migration to Swift. You can check it out here.
What worked for me was using a bridging header while doing the migration to Swift. You can check it out here.
Thanks for the tip! Would you mind sharing how you did it exactly? That would really help a lot. π
change:AppDelegate.swift
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { self.moduleName = "beidou_aiot" self.dependencyProvider = RCTAppDependencyProvider()
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = [:]
let didLaunchFinish = super.application(application, didFinishLaunchingWithOptions: launchOptions)
let rnSplashScreenHelper = RNSplashScreenHelper()
rnSplashScreenHelper.show()
return didLaunchFinish
}
add:RNSplashScreenHelper.h
#ifndef RNSplashScreenHelper_h #define RNSplashScreenHelper_h
#import <Foundation/Foundation.h>
@interface RNSplashScreenHelper : NSObject
- (void) show;
@end
#endif /* RNSplashScreenHelper_h */
add:RNSplashScreenHelper.m
#import "RNSplashScreenHelper.h" #import "RNSplashScreen.h" @implementation RNSplashScreenHelper
- (void) show { [RNSplashScreen show]; }
@end
add your project name-Bridging-Header.h
#import "RNSplashScreenHelper.h"
I got issue splash screen stuck forever ios
To set up react-native-splash-screen on iOS:
Install the package:
npm install react-native-splash-screen --save
cd ios && pod install
In AppDelegate.swift, add:
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
// your existing code...
RNSplashScreen.show() // Show splash screen
return true
}
Create (or edit) the bridging header file: abcproject-Bridging-Header.h
#import "RNSplashScreen.h"
If the bridging header doesnβt exist, create it and then go to: Xcode β Build Settings β Swift Compiler - General β Objective-C Bridging Header and set its path (e.g. $(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h).