Eddie Hinkle


Swift Question: Swift Package error when relying on AuthenticationServices

Okay, so for anyone reading that is familiar with Swift/Apple development and more importantly, with Xcode 11 beta.

I am building a Swift Package using Xcode 11 beta. It's called IndieWebKit, but the issue I'm running into is one of the classes relies on AuthenticationServices because it uses OAuth 2.0 and Apple rejects any app that doesn't use ASWebAuthenticationSession for OAuth 2.0

So here is the issue, when build the package and run it's tests, it errors out because it says "Library Not Loaded" for AuthenticationServices.

Below are what I've implemented to try to get it to work:

I added #if canImport(AuthenticationServices) around import AuthenticationServices to try to avoid importing it if it's not available. I've also set the Swift package platforms to macOS(v10_15) and iOS(v12).

I also tried adding @available(iOS 12.0, macOS 10.15, *) at the beginning of the function that utilizes ASWebAuthenticationSession.

In the test suite, I DO NOT call the function that uses ASWebAuthenticationSession within the tests.

Despite all of this, I can ONLY run my tests if I have commented out the import and the usage of ASWebAuthenticationSession. This works for now while I'm doing initial development, but eventually I need to be able to run these tests AND have the package contain the ASWebAuthenticationSession call.

I believe the reason it's doing this is because I'm still on macOS 10.14 (which doesn't have AuthenticationServices), but I feel like if I'm add these various "available if and can import" statements, I should be able to run tests that don't run the function that requires those services.

Any thoughts or ideas would be super helpful. Thanks!

88.08 ℉🌧Frederick, Marylandtechswiftquestion
posted using quill.p3k.io
Please note: This site is in an active redesign. Some things might be a little off 🧐