Description:
I followed instructions from https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup and i'm getting the following error in the NotificationService.swift file:
Use of unresolved identifier 'RCTOneSignalExtensionService'
In the following lines:
RCTOneSignalExtensionService.didReceive(self.receivedRequest, with: self.bestAttemptContent);
RCTOneSignalExtensionService.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent);
(your description here)
React native version
react-native-cli: 2.0.1
react-native: 0.55.3
OneSignal React-Native SDK version
3.2.4
How did you add the SDK to your project (eg. npm)
Through npm
npm install --save react-native-onesignal
react-native link
Steps to Reproduce Issue:
Install the latest react-native-onesignal package
Replace content from NotificationService.swift (copied from https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup) with:
`import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var receivedRequest : UNNotificationRequest!;
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
self.receivedRequest = request;
RCTOneSignalExtensionService.didReceive(self.receivedRequest, with: self.bestAttemptContent);
if let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
RCTOneSignalExtensionService.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent);
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}`
Also when i open the app i'm getting the following error when i try to init OneSignal:
Cannot read property 'initWithAppId' of undefined
@gustavomanolo Are you sure you created the Objective-C bridging header and imported RCTOneSignal into it...?
Closing due to no response...
Hi @Nightsd01 I am facing the same issue.i have created the Objective-C bridging header and imported RCTOneSignal
It looks like this
#ifndef Objective_CBridgingHeader_h
#define Objective_CBridgingHeader_h
#import "RCTOneSignalExtensionService.h"
#endif
but still i am getting the same error
Having the same issue... tried switching to objective-c to see if that would solve it but only getting
fatal error: 'RCTOneSignalExtensionService.h' file not found
@sksahil030 did you find a solution?
Any updates on this? Just like @yarism, I have the same issue even though i have created the header file.
@yarism No, i couldn't find any solution for it
@yarism @sksahil030
I had the same problem. I've solvd it by targeting OneSignalNotificationService, selecting Build Settings, finding 'Objective-C Bridging Header' and adding path to the previously made Objective-C header file. Soemthing like "your project/OneSignalNotificationServiceExtension/Header.h"
I know this issue is closed but I am experiencing the same issue within my NotificationService.swift in the OneSignalNotificationServiceExtension folder. Specifically the Use of unresolved identifier 'RCTOneSignalExtensionService' error.
I proceeded to create a header file within the same folder directory much like @sksahil030
#ifndef OneSignalNotificationServiceExtension_Swift_h
#define OneSignalNotificationServiceExtension_Swift_h
#import "RCTOneSignalExtensionService.h"
#endif /* OneSignalNotificationServiceExtension_Swift_h */
In the OneSignalNotificationService target > Build Settings. I have specified the following Objective-C Bridging Header path, as mentioned by @nord2ost
$(SRCROOT)/../node_modules/react-native-onesignal/ios/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension-Swift.h
After running react-native run-ios the error message I am getting indicates it cannot find the NotificationServiceExtension-Swift.h file specified in the Objective-C Bridging Header path. I am sure that is the correct path to file.
Main questions: If creating the Objective-C Bridging Header and adding in #import "RCTOneSignalExtensionService.h"
is the solution what is the correct way to implement?
How to resolve *Use of unresolved identifier 'RCTOneSignalExtensionService' error.*
Thanks.
I must apologize, it was an incorrect path issue. The above steps of creating a header file and then specifying the path in the Objective-C Bridging Header path of the OneSignalNotificationService target was the solution for me. Thanks.
For anyone having issues with this: clarifying @nord2ost
In the OneSignalNotificationService folder > Build Settings > Header Search Paths add $(SRCROOT)/../node_modules/react-native-onesignal/ios
Create a bridge header and name it whatever you want. and add
#import "RCTOneSignalExtensionService.h"
so it looks like
#ifndef YOUR_NAMED_HEADER
#define YOUR_NAMED_HEADER
#import "RCTOneSignalExtensionService.h"
#endif /* YOUR_NAMED_HEADER */
Go back into OneSignalNotificationService, selecting Build Settings, finding 'Objective-C Bridging Header' and add
$(SRCROOT)/OneSignalNotificationServiceExtension/YOUR_NAMED_HEADER.h
Thanks for the clear instructions @vinceprofeta, saved me a ton of time. Some of this stuff isn't immediately obvious for us with limited native iOS dev experience.
OneSignalNotificationServiceExtension target > Build Settings > Header Search Paths
Add $(SRCROOT)/../node_modules/react-native-onesignal/ios
as recursive
Most helpful comment
For anyone having issues with this: clarifying @nord2ost
In the OneSignalNotificationService folder > Build Settings > Header Search Paths add
$(SRCROOT)/../node_modules/react-native-onesignal/ios
Create a bridge header and name it whatever you want. and add
#import "RCTOneSignalExtensionService.h"
so it looks like
Go back into OneSignalNotificationService, selecting Build Settings, finding 'Objective-C Bridging Header' and add
$(SRCROOT)/OneSignalNotificationServiceExtension/YOUR_NAMED_HEADER.h