Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'sharedApplication' is unavailable: not available on iOS (App Extension) #1272

Closed
Zurdge opened this issue Aug 24, 2021 · 7 comments
Closed

Comments

@Zurdge
Copy link

Zurdge commented Aug 24, 2021

Description:
I'm trying to configure OneSignal for iOS however I'm getting an error saying "'sharedApplication' is unavailable: not available on iOS

/Users/jamesburdge/Documents/GitHub/morasun-app/node_modules/react-native/React/Base/RCTKeyCommands.m:131:44: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

from file RCTKeyCommands.m

I've followed this guide and double checked everything
https://documentation.onesignal.com/docs/react-native-sdk-setup
https://documentation.onesignal.com/docs/ios-sdk-app-groups-setup

Pod File

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
pod 'react-native-twilio-video-webrtc', path: '../node_modules/react-native-twilio-video-webrtc'
pod 'RNFS', :path => '../node_modules/react-native-fs'

platform :ios, '11.0'


target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignal', '>= 3.0', '< 4.0'
end

target 'MorasunApp' do
  use_unimodules!
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  pod 'RNFS', :path => '../node_modules/react-native-fs'

  pod 'react-native-background-timer', :path => '../node_modules/react-native-background-timer'

  target 'MorasunAppTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
  end
end

Environment

...
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-onesignal": "^4.0.3",
...

Adding modules via npm install

Screenshot 2021-08-24 at 19 43 01

@Zurdge
Copy link
Author

Zurdge commented Aug 24, 2021

Its shocking how the answers click into place after posting a issue on Github.

I needed to make a change to my post_install section of my apps PodFile


....

# Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)

    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
        end
      end

  end
end

I consider this more of a patch, I don't really know why it works but it does. If there is a better practice someone knows about I'd be keen to know.

@rgomezp
Copy link
Contributor

rgomezp commented Sep 3, 2021

Howdy,
Believe me I've been there! I believe this is a cocoa pods-specific issue. For a longer term fix, maybe try re-installing cocoapods and then re-installing all pods.

Hope this helps. Otherwise, it looks like you fixed it!

Enjoy!

@rgomezp rgomezp closed this as completed Sep 3, 2021
@farukozdemirz
Copy link

Above solution didn't work for me.
Podfile:


....

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end
    end
  end
end


Environment

... "react": "17.0.1", "react-native": "0.65.1", "react-native-onesignal": "^4.3.1", ...

After applying the above change:

Undefined symbol: OBJC_CLASS$_RCTInspectorDevServerHelper

@mstankov
Copy link

Above solution didn't work for me. Podfile:


....

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end
    end
  end
end

Environment

... "react": "17.0.1", "react-native": "0.65.1", "react-native-onesignal": "^4.3.1", ...

After applying the above change:

Undefined symbol: OBJC_CLASS$_RCTInspectorDevServerHelper

Same here. Initial problem as described in the issue was fixed by adding APPLICATION_EXTENSION_API_ONLY = 'NO' to each build. Now i'm getting Undefined symbols x86_64 error for RNPermissionHandlerNotifications in my case

Has anyone figured it out?

@SafiDS
Copy link

SafiDS commented Oct 23, 2021

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.

Sample Pod File

`require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'AppName' do

permissions_path = '../node_modules/react-native-permissions/ios'

pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"

config = use_native_modules!

pod 'JWPlayer-SDK', '~> 3.16.0'

use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change false to true and then install pods
:hermes_enabled => false
)

target 'PlucTvTests' do
inherit! :complete
# Pods for testing
end
use_flipper!()

post_install do |installer|
react_native_post_install(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
end

target 'OneSignalNotificationServiceExtension' do
pod 'OneSignal', '>= 3.0', '< 4.0'
end
`

@yadigar-prospr
Copy link

Additional info in case someone faces, if you're using Realm or somehow enabled use_frameworks!. You have to put it outside of target 'your_app' do

End of the day it must look like this:

use_frameworks! :linkage => :static
target 'myApp' do
  $static_framework = []
  ...
end

target 'myExtension' do
...
end

@emincer
Copy link

emincer commented Apr 25, 2024

I'm having this issue now using

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants