HwangTaehyun / react-native-lottie-splash-screen

⚡ Lottie splash screen for your react native app!
MIT License
222 stars 62 forks source link

Unable to complete setup on iOS + App crashes the second the time it is opened on Android #39

Closed supmanyu closed 2 years ago

supmanyu commented 2 years ago

Run react-native info in your project and share the content:

System:
    OS: macOS 12.0.1
    CPU: (8) arm64 Apple M1
    Memory: 172.20 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v14.17.0/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
    Watchman: 2022.05.30.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.64.3 => 0.64.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

What react-native-splash-screen version are you using?: v3.3.0

What platform does your issue occur on? (Android/iOS/Both): iOS (Cannot complete setup) / Android (App crashes when it's opened the second time)

Describe your issue as precisely as possible :

Hi @HwangTaehyun, I have tried to follow the implementation guide for iOS, but cannot complete the integration steps, since XCode gives me an error in the Dynamic.swift file that it Cannot find RNSplashScreen in given scope, and because of this the identifier Dynamic is not found in AppDelegate.m. I have read the older issues which were similar to mine and have tried the following fixes:

  1. Deleted derived data for the workspace
  2. Created the Dynamic.swift file from XCode instead of VSCode
  3. Import 'projectName-Swift.h' into AppDelegate.h instead of AppDelegate.m
  4. Restarting my computer

Also on Android the App builds successfully, but force closes the second time it is opened after installation

Join a screenshot or video of the problem on the simulator or device:

Directory structure: image

Dynamic.swift: image

AppDelegate.m image

Show us the code you are using? AppDelegate.m:

#import "AppDelegate.h"
#import "RNFBMessagingModule.h"

#import <React/RCTBridge.h>
#import <React/RCTLinkingManager.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"  // <- add the header import
#import <Firebase.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <UserNotifications/UserNotifications.h>
#import <RNCPushNotificationIOS.h>
#import <CodePush/CodePush.h>
#import "edufund-Swift.h"
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
// #import <EXSplashScreen/EXSplashScreenService.h>
#import <UMCore/UMModuleRegistryProvider.h>

#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <React/RCTDevLoadingView.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

@implementation AppDelegate

@synthesize launchOptions;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if DEBUG
  InitializeFlipper(application);
#endif
  self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];

  if ([FIRApp defaultApp] == nil) {
    // [FIRApp configure];
    NSString *filePath;
    #ifdef DEBUG
      NSLog(@"[FIREBASE] Development mode.");
      filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Debug"];
    #else
      NSLog(@"[FIREBASE] Production mode.");
      filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Release"];
    #endif
    FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
    [FIRApp configureWithOptions:options];
  }

  // Define UNUserNotificationCenter
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;

  [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

  // onedirect -start
  [OnedirectSdkClass configureOnedirectChatSdkWithBrandCustomerId:@"QWERTY123"];
  // onedriect -end

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:self.launchOptions];
  #if DEBUG
    [bridge moduleForClass:[RCTDevLoadingView class]];
  #endif
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"main" initialProperties:appProperties];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:0.01 green:0.06 blue:0.19 alpha:1.00];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
//   self.window.rootViewController = rootViewController;
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"BootSplash" bundle:[NSBundle mainBundle]];
    UIViewController *ViewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

    ViewController.view.frame = self.window.bounds;
    rootView.loadingView = ViewController.view;
self.navController = [[UINavigationController alloc]
initWithRootViewController:rootViewController];
self.navController.navigationBarHidden=YES; // fix status bar issue
self.window.rootViewController = self.navController;
// self.window.rootViewController = rootViewController;

  [self.window makeKeyAndVisible];

  Dynamic *t = [Dynamic new];
  UIView *animationView = [t createAnimationViewWithRootView:rootView lottieName:@"loading"]; // change lottieName to your lottie files name
  animationView.backgroundColor = [UIColor whiteColor]; // change backgroundColor

  // register LottieSplashScreen to RNSplashScreen
  [RNSplashScreen showLottieSplash:animationView inRootView:rootView];

  // play
  [t playWithAnimationView:animationView];

  // If you want the animation layout to be forced to remove when hide is called, use this code
  [RNSplashScreen setAnimationFinished:true];

  [super application:application didFinishLaunchingWithOptions:launchOptions];

  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 {
 #ifdef DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
 #else
  return [CodePush bundleURL];
 #endif
}

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
  completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}

// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];

  [OnedirectSdkClass deliverDeviceTokenWithDeviceToken:deviceToken];
}

// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}

// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
  [RNCPushNotificationIOS didReceiveNotificationResponse:response];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  BOOL handledFB = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:options         [UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];

  BOOL handleCustom = [RCTLinkingManager application:application openURL:url options:options];
  return handledFB || handleCustom;
}

// Only if your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html).
// Add this above `@end`:
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
  return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

@end
mikolaj-kozera-prpl-global commented 2 years ago

I have the same issue

HwangTaehyun commented 2 years ago

Firstly, you should install Lottie module!

Secondly, you should check this option in Xcode.

image

I added examples for ios and android today. Then I checked again, there was no problem!

Thank you!

HwangTaehyun commented 2 years ago

My Bridging-Header file image

And My AppDelegate.m file. image

HwangTaehyun commented 2 years ago

The location of the Bridging-Header file seems to be the problem.

codeOlam commented 2 years ago

Hi @HwangTaehyun, Please how did you come about this examples-Swift.h import. I get an error: `fatal error: 'ten15-Swift.h' file not found

import "ten15-Swift.h" // here, change project name to yours`

codeOlam commented 2 years ago

Hi @HwangTaehyun , I was able to resolve the issue.

I am running XCode v13. so I have to create the Dynamic.swift from XCode and allowed Xcode to add the bridging header file for me. I went ahead to copy and paste the code from the documentation for the Dynamic and bridging headers respectively. The screenshots you also provided above in the issue help alot.

Thank you @HwangTaehyun

HwangTaehyun commented 2 years ago

@codeOlam I'm glad it worked well!

ramprakashreddy commented 2 years ago

@codeOlam i am also facing the same issue, can you please share a screenshot of the project file structure, i tried all of it but it still throws an error file not found, and to which folder have you added the files from xcode?

codeOlam commented 2 years ago

@ramprakashreddy, I figured i had to create the Dynamic.swift file directly from xcode instead of using VScode (in my case as code editor). Then i allowed xcode to create the bridging header file for me. Then I went ahead to copy and paste the code from the documentation for the Dynamic and bridging headers respectively.

attached is the screenshot of the file structure, it is still same as the one shared on this issue above.

image

let me know if this was clear enough.

ramprakashreddy commented 2 years ago

@ramprakashreddy, I figured i had to create the Dynamic.swift file directly from xcode instead of using VScode (in my case as code editor). Then i allowed xcode to create the bridging header file for me. Then I went ahead to copy and paste the code from the documentation for the Dynamic and bridging headers respectively.

attached is the screenshot of the file structure, it is still same as the one shared on this issue above.

image

let me know if this was clear enough.

@codeOlam thanks for the screenshot i had the same folder structure, still i get the file not found error, which version of xcode are you using?