Description:
I've followed the instructions for React Native SDK from here - https://documentation.onesignal.com/docs/react-native-sdk-setup
I've added the npm package, performed react-native link
and also pod install
. Everything went smooth.
Then I proceed to create the Notification Extension. When I get to the part where I'm instructed to add libRCTOneSignal.a
in the Link Binary with Libararies
setting, I'm not able to find it in the list that Xcode shows. Here's all I see when I search for One Signal:
Here is my header search pages setting:
Now I tried adding the libreact-native-onesignal.a
, but when building I get this linking error:
ld: library not found for -lreact-native-onesignal
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Environment
3.2.6
0.55.4
9.2
Turns out react-native link
did not work correctly as usual :D I just had to manually add the RCTOneSignal
project into Libraries
and then I was able to add libRCTOneSignal.a
I think it would be nice if you guys can add the instructions for manually linking in addition to react-native link
so people can verify if link worked correctly :)
how did you add it ?
Also trying to figure out exactly how to add the RCTOneSignal project into Libraries
@nickyhajal @abdul-elah-js @steverob Can someone explain how to manually add the RCTOneSignal
project into Libraries
?
This problem should be in documentation as well.
@pacozaa you can follow Facebook's instructions here: https://facebook.github.io/react-native/docs/linking-libraries-ios
Open node_modules/react-native-onesignal/ios then drag and drop RCTOneSignal.xcodeproj to XCode project folder Libraries, then the libRCTOneSignal.a will appear on the search.
I have updated the documentation in the React-Native setup to reflect this. Thanks for bringing this up and helping make our documentation better!
No Libraries folder.
@rgomezp Sorry, could you please reopen the issue? libRCTOneSignal.a cannot be found in extension in Xcode 12. But works on Xcode 11.7
@MrAlekhin ,
Try going into the ios
directory and running pod deintegrate && pod install
This is happening for me in Xcode 12. Not using pods.
Howdy,
It sounds like this is an issue for those of you who are using Xcode 12 and are _not_ using Cocoapods.
Reopening to track this issue.
Another using Xcode 12 without using pods that have the same problem. :(
Had to move the lib to pods, but it's not working on my staging target😢 guys please review that ASAP 🙏
@rgomezp sorry, any updates on that? tried to use cocoapods but OneSignal is not initialized for some reason. using React Native 0.59
Having issues with react-native-onesignal
. Here is the Pod example:
# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'
target 'example' do
# Comment the next line if you don't want to use dynamic frameworks
# Pods for example
pod 'Branch', '0.28.1'
pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal'
pod 'React', :path => '../node_modules/react-native/'
end
target 'exampleDev' do
# Comment the next line if you don't want to use dynamic frameworks
# Pods for exampleDev
pod 'Branch', '0.28.1'
pod 'React', :path => '../node_modules/react-native/'
pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal'
end
target 'OneSignalNotificationServiceExtension' do
# Comment the next line if you don't want to use dynamic frameworks
pod 'OneSignal', '>= 2.14.2', '< 3.0'
# Pods for OneSignalNotificationServiceExtension
end
target 'DevOneSignalNotificationServiceExtension' do
# Comment the next line if you don't want to use dynamic frameworks
pod 'OneSignal', '>= 2.14.2', '< 3.0'
# Pods for DevOneSignalNotificationServiceExtension
end
@rgomezp is anyone looking into this?
Our project uses react-native 0.59 (no cocoapods) and it's not building on XCode 12 because of the issue here
@rgomezp is anyone looking into this?
Our project uses react-native 0.59 (no cocoapods) and it's not building on XCode 12 because of the issue here
Same here. react-native 0.59 and Xcode 12 after last update i have the error described. All working fine before update. I even removed and reinstalled react-native-onesignal 3.9.2
clang: error: no such file or directory: '/Users/leonardo/Library/Developer/Xcode/DerivedData/xxxxx/Build/Products/Debug-iphonesimulator/libRCTOneSignal.a'
Command Ld failed with a nonzero exit code
Update 1:
If i build the app for production it works...The problem is when i try to run on simulator (all of them with different iOS)
Update 2:
I can debug even on physical device.
Update 3:
I can debug but onesignal does not prompt user consent so notifications not working. I even updated latest version 3.9.2.
The solution for me was to downgrade xcode to 11.7 and use a backup of ios folder. The problem seems to be related to xcode 12+
I tried to downgrade the XCode, as @Tebrynn said, but I continue getting the same issue.
For me, the only solution was to replace the manual installation with the Cocoapods installation.
I just followed the instructions in the documentation (https://documentation.onesignal.com/docs/react-native-sdk-setup).
Any solution for this?
I just updated to Xcode12 and I am facing this error on build too.
I recently updated to Xcode 12. I'm getting the same problem with not finding libRCTOneSignal.a. I believe I followed the steps and workarounds others have tried. I'm stumped.
I read several articles about excluding arm64 for OneSignal. I tried these with no luck so far. However, since it only affects the simulator, I will probably not spend much more time on this issue.
Same issue, Xcode 12.4 and RN 0.59.10.
Same issue here.
Howdy,
It sounds like manual installations broke somehow. We will need to dig further to investigate.
Thanks for your patience.
In the meantime, if possible, try switching to a Cocoapods installation method
I am facing the same issue. Any solution?
Hello, as of React-Native-OneSignal version 4.0.0 the binary contained in the RCTOneSignal.xcodeproj is not be updated meaning that you will need to use Cocoapods to add OneSignal to the NotificationServiceExtension.
You can do so by adding the following to your Podfile:
target 'OneSignalNotificationServiceExtension' do
pod 'OneSignal', '>= 3.0', '< 4.0'
end
Then update the NotificationService file to the following if you are using Swift
import UserNotifications
import OneSignal
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var receivedRequest: UNNotificationRequest!
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request;
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: self.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.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
OneSignal.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
}
Or the following if you are using Objective-C
#import <OneSignal/OneSignal.h>
#import "NotificationService.h"
@interface NotificationService ()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.receivedRequest = request;
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
[OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
// DEBUGGING: Uncomment the 2 lines below and comment out the one above to ensure this extension is excuting
// Note, this extension only runs when mutable-content is set
// Setting an attachment or action buttons automatically adds this
// NSLog(@"Running NotificationServiceExtension");
// self.bestAttemptContent.body = [@"[Modified] " stringByAppendingString:self.bestAttemptContent.body];
self.contentHandler(self.bestAttemptContent);
}
- (void)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.
[OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
self.contentHandler(self.bestAttemptContent);
}
@end
The complete setup guide can be found here
Most helpful comment
Turns out
react-native link
did not work correctly as usual :D I just had to manually add theRCTOneSignal
project intoLibraries
and then I was able to addlibRCTOneSignal.a
I think it would be nice if you guys can add the instructions for manually linking in addition to
react-native link
so people can verify if link worked correctly :)