Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App Sandbox blocking FirebaseApp.configure() on macOS with SwiftUI

I am writing an app for both macOS and iOS.

When I started my multiplatform project, I decided to see if the Firebase SDKs work with macOS, because I have seen this error before:

tvOS and macOS SDK support is not part of the official Firebase product. Instead they are community supported. Details at https://github.com/firebase/firebase-ios-sdk/blob/master/README.md.

I went to start configuring Firebase, and had to create an NSApplicationDelegate for it to work on macOS:

class AppDelegate: NSObject, NSApplicationDelegate {
    func applicationDidFinishLaunching(_ notification: Notification) {
        FirebaseApp.configure()
    }
}

And then I attached this AppDelegate to my @main App with a NSApplicationDelegateAdaptor:

@main
struct SchedulerApp: App {
    @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Tested it first with a simple print statement - and it worked.

Tested it then with FirebaseApp.configure(), and it threw a whole bunch of errors.

Sandbox does not allow access to com.apple.dnssd.service

dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:4 Err:-1 Errno:1 Operation not permitted

nw_resolver_create_dns_service_locked

Connection 1: received failure notification

Connection 1: failed to connect 10:-72000, reason -1

Connection 1: encountered error(10:-72000)

A server with the specified hostname could not be found.

And the last one contained a URL, https://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog.

From the error code, I did some digging online, and because I am new to macOS development, found out about App Sandbox. I then tried turning it off in Signing and Capabilities and running the project again.

No errors. Worked fine!

How do I allow the server to connect through App Sandbox because I do want to publish the app in the near future and want to get started porting my SwiftUI iOS app over to macOS, as you cannot upload an app to the Mac app store without App Sandbox?

like image 602
Tahmid Azam Avatar asked Nov 14 '20 20:11

Tahmid Azam


1 Answers

Fixed it by checking box

Incoming network connections (server)

and

Outgoing network connections (client)

in target settings (screen where you can edit the name and version of your app) > Signing & Capabilities. If you get an error saying your entitlements folder was edited, just clean the build folder.

like image 85
Tahmid Azam Avatar answered Nov 12 '22 04:11

Tahmid Azam