Solvedreact native onesignal OneSignalNotificationServiceExtension causes sharedApplication build issues

Description:
Adding the target OneSignalNotificationServiceExtension causes my app to be unable to build, due to being unable to use certain things in app extensions... in this case, the error is specifically about sharedApplication (it actually shows up as a problem in RCTRedBox.m). The app builds fine, even with react-native-onesignal, until I add the extension.

Environment
react-native-onesignal: 3.3.3
react-native: 0.59.9

SDK added via yarn, then react-native link react-native-onesignal

Steps to Reproduce Issue:

I haven't had the time to attempt to reproduce in an app other than mine... On my app (so presumably others?):

Install SDK via yarn
Link package
pod install
Add extension following instructions from https://documentation.onesignal.com/docs/react-native-sdk-setup#section-usage
Attempt to build

Anything else:

All in the description

14 Answers

✔️Accepted Answer

Went through this exact same issue and like @indapublic did, I had added the extension to my Podfile incorrectly. Just wanted to add some clarity.

This issue arises when you add Service's target inside your app's target.

This is wrong:

target 'app' do
  rn_path = '../node_modules/react-native'
  ....
  target 'OneSignalNotificationServiceExtension' do
    pod 'OneSignal', '>= 2.9.3', '< 3.0'
  end
end

This is correct:

target 'app' do
  rn_path = '../node_modules/react-native'
  ....
 end
 target 'OneSignalNotificationServiceExtension' do
    pod 'OneSignal', '>= 2.9.3', '< 3.0'
 end

This snippet needs to be its own top-level target and not a sub-target of your app.

Once corrected just run pod install again.

Other Answers:

Hi, @rgomezp . I have this error with 3.4.1 at the moment.

node_modules/react-native/React/DevSupport/RCTDevLoadingView.m:77:42: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

Not sure if this applies to your library, but I’ll inform you

More Issues: