I have the following that emits an event from my iOS app to React Native.
iOS
- (void)sendBrazeDeepLinkUrlToReactNative: (NSString *) payload {
if (hasListeners) {
[self sendEventWithName:@"incomingRNAppEvent" body:@{@"url":payload}];
}
}
And then I listen for the event in my React Native App.
const AppNotificationEmitter = new NativeEventEmitter(AppNotification);
const subscription = AppNotificationEmitter.addListener(
"incomingRNAppEvent",
(event: any) => {
console.log("InAppMessage Recieved: ", JSON.stringify(event));
console.log("AppNotification: ", event);
}
);
When the event occurs, I am getting the event triggered and everything works as expected EXCEPT...
The event object received in React Native contains an empty object???
e.g. the output from `console.log("AppNotification", event) is:
AppNotification: {"url": null}
and I was able to confirm that the URL was definitely set by debugging the iOS native module, and checking the value when the event is triggered. i.e. payload was a valid url.
Ok, turns out my knowledge of Objective-C was the issue. The object coming into my sendBrazeDeepLinkUrlToReactNative was getting a NSURL * rather than NSString
This code works.