Compilation error on iOS with react-native 0.68
With react-native 0.68 the AppDelegate has been converted from ObjC (.m) to ObjC++ (.mm).
This leads to a first compilation error: Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules on this line: https://github.com/bamlab/react-native-batch-push/blob/5bad30e1896d30d98a6b13bca1e4dd60f99f99e8/ios/RNBatch.h#L13
This error can be fixed by adding -fcxx-modules to OTHER_CPLUSPLUSFLAGS project build settings. It should be written to installation guide.
After the fix of this first error, I got an other one : Definition of type 'NSUInteger' conflicts with typedef of the same name on a file of iOS Batch native SDK. I created an issue for this: https://github.com/BatchLabs/Batch-iOS-SDK/issues/29. When a fix will be available you should bump your package with the fixed version of the native SDK.
Another thing: I think adding pod 'Batch', '~>1.18' like specified in the Readme: https://github.com/bamlab/react-native-batch-push/blob/5bad30e1896d30d98a6b13bca1e4dd60f99f99e8/README.md?plain=1#L28
is useless because your native package RNBatchPush already defines the native SDK dependency in https://github.com/bamlab/react-native-batch-push/blob/5bad30e1896d30d98a6b13bca1e4dd60f99f99e8/ios/RNBatchPush.podspec#L17
and because you didn't specified a version, the dependency resolution of Cocoapods takes the latest version. In my case Cocoapods installed Batch 1.19 even if I have Batch 1.18 specified in Podfile. If you want specify a precise version of Batch you should precis it in RNBatchPush.podspec
Would reverting to an old #import <Batch/Batch.h> syntax fix the issue with no other cflag?
#import <Batch/Batch.h> is working well and does not require the C++ flag -fcxx-modules 🙂
hmm, if i change #import "RNBatch.h" to #import <Batch/Batch.h> I then get a different error:
error: use of undeclared identifier 'RNBatch'; did you mean 'rpmatch'?
[RNBatch start];
The import that should be replaced is the one in RNBatch, not RNBatch itself (which is why you're seeing those errors)
ahh so you've used something like patch-package for now to do that?
Exactly! This is my patch package: patches/@bam.tech+react-native-batch+7.0.3.patch:
diff --git a/node_modules/@bam.tech/react-native-batch/ios/RNBatch.h b/node_modules/@bam.tech/react-native-batch/ios/RNBatch.h
index 7ba6fcb..bd3259b 100644
--- a/node_modules/@bam.tech/react-native-batch/ios/RNBatch.h
+++ b/node_modules/@bam.tech/react-native-batch/ios/RNBatch.h
@@ -10,7 +10,7 @@
#import "RCTEventEmitter.h"
#endif
-@import Batch;
+#import <Batch/Batch.h>
#define PluginVersion "ReactNative/7.0.3"
Also running into this error, thanks for the patch @alois-beto
Thanks @alois-beto for your contribution. I'm closing this issue as Batch released a new version and this repository is being archived. This should be addressed in https://github.com/BatchLabs/Batch-React-Native-Plugin