exponea / exponea-react-native-sdk

MIT License
8 stars 13 forks source link

AppDelegate.h changes not working with React Native 0.71.8 #95

Closed rosiearms closed 1 year ago

rosiearms commented 1 year ago

I am upgrading our React Native version to 0.71.8. The upgrade helper makes some changes to the AppDelegate.h:

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : RCTAppDelegate

@end

But these changes don't seem to work with the changes required for the iOS exponea push notification configuration:

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

@interface AppDelegate : ExponeaRNAppDelegate<RCTBridgeDelegate>
@end

When I make the above change I get build errors:

❌  /Users/*/*ios/*/AppDelegate.mm:20:8: property 'moduleName' not found on object of type 'AppDelegate *'

  self.moduleName = @"armobileapp";
           ^

❌  /Users/*/*/ios/*/AppDelegate.mm:23:8: property 'initialProps' not found on object of type 'AppDelegate *'

  self.initialProps = @{};

Are there any changes needed here to support the React Native version I'm upgrading to?

adam1929 commented 1 year ago

Hi @rosiearms I think that this is not SDK related issue. TBH upgrade helper creates some problem for us too :-) Anyway, I think that you used upgrade helper, app has been re-builded; Then you update AppDelegate class but .mm file has not been updated-rebuilded.

rosiearms commented 1 year ago

Hi @adam1929 thanks for gettings back to me. I got these build errors after updating the .mm files and re-building, so I don't think it's that. I have also just tried a new React Native project, on version 0.71.8 of RN and the latest version of the exponea SDK and I also get the same build errors when making the changes for push notifications.

AppDelegate.h

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

@interface AppDelegate : ExponeaRNAppDelegate <RCTBridgeDelegate>
@end

AppDelegate.mm

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"ProjectNameHere";
  // 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 = @{};

  [super application:application didFinishLaunchingWithOptions:launchOptions];
  return YES;
}

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

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
  return true;
}

@end

build errors:


  self.moduleName = @"ProjectNameHere";
                                       ^

❌  /Users/<user>/ProjectNameHere/ios/ProjectNameHere/AppDelegate.mm:12:8: property 'initialProps' not found on object of type 'AppDelegate *'

  self.initialProps = @{};

It seems to be because RCTAppDelegate has moduleName and initialProps variables that are used in AppDelegate.mm, but the ExponeaRNAppDelegate overrides this and RCTAppDelegate is not extended, so we have no access to those variables.

Are you able to replicate this or provide a way to get around this issue?

ejjsharpe commented 1 year ago

We are struggling with this as this issue as well. Is there any update on this? Installation steps no longer work on a fresh React Native project at 0.71.8

adam1929 commented 1 year ago

Hi guys, RCTAppDelegate is optional to use for 0.71+ and yes It has promised benefits. Unfortunately SDK is not able to extend it because older RN build (pre 0.71) doesn't know about it. There are still some developers using older RNs. You have 2 options:

I would prefer second option because RN is updating quite often so any changes should be handled by RCTAppDelegate (as they are promising) and copy of ExponeaRNAppDelegate methods are one-time job :-) Thank you for reporting