Skip to content

Changes in AppDelegate from Objective-C to Swift in React Native 0.77 and Above #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kasumil opened this issue Feb 21, 2025 · 9 comments

Comments

@kasumil
Copy link

kasumil commented Feb 21, 2025

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?

@jagnesh
Copy link

jagnesh commented Feb 23, 2025

🚀 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! 🚀✨

@muammadibal
Copy link

🚀 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! 🚀✨

how to use in old AppDelegate instead swift?

@kasumil
Copy link
Author

kasumil commented Feb 24, 2025

umm...I was in a hurry, so I used react-native-bootsplash.

@jagnesh
Copy link

jagnesh commented Feb 24, 2025

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! 🎉

@sandipshiwakoti
Copy link

sandipshiwakoti commented Feb 24, 2025

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):

  1. Delete AppDelegate.swift.
  2. Recreate (refer to Upgrade Helper):
    • AppDelegate.h
    • main.m
    • AppDelegate.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. 🚀

⚠️: If you don't want to migrate to Swift, this solution is for you. If you prefer to stay with Swift in the long term since React Native is heading towards Swift, consider exploring a Swift migration.

@jesusej
Copy link

jesusej commented Mar 24, 2025

What worked for me was using a bridging header while doing the migration to Swift. You can check it out here.

@corderov
Copy link

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. 🙏

@jvssoft
Copy link

jvssoft commented Apr 24, 2025

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants