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

build error UIApplication.shared is unavailable in app extension #176

Closed
everwanna opened this issue Jul 2, 2019 · 3 comments
Closed

build error UIApplication.shared is unavailable in app extension #176

everwanna opened this issue Jul 2, 2019 · 3 comments

Comments

@everwanna
Copy link

'shared' is unavailable: Use view controller based solutions where appropriate instead.

I use QRCodeReader in an app extension. Xcode reports the error in,

  @objc public func setNeedsUpdateOrientation() {
    setNeedsDisplay()

    overlayView?.setNeedsDisplay()

    if let connection = reader?.previewLayer.connection, connection.isVideoOrientationSupported {
      let application                    = UIApplication.shared
      let orientation                    = UIDevice.current.orientation
      let supportedInterfaceOrientations = application.supportedInterfaceOrientations(for: application.keyWindow)

      connection.videoOrientation = QRCodeReader.videoOrientation(deviceOrientation: orientation, withSupportedOrientations: supportedInterfaceOrientations, fallbackOrientation: connection.videoOrientation)
    }
  }

UIApplication.shared is not available in app extension.

@nderkach
Copy link

nderkach commented Jul 3, 2019

See #169

@everwanna
Copy link
Author

Thanks!

@yannickl
Copy link
Owner

yannickl commented Oct 8, 2019

Are you using CocaPods? If so you can set the *Require Only App-Extension-Safe API * to NO your target.

Add the following lines in your Podfile:

post_install do |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

@yannickl yannickl closed this as completed Oct 8, 2019
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

3 participants