Can a Mac Catalyst app manage a different iOS firestore database? If so how to config it

Viewed 291

How can I point a Mac Catalyst App to another firestore area so 2 editor users can easily manage their data from their laptops?

Background: I have a fully functioning iOS app using a Google firestore DB. A couple of users are editors but currently have to choose images and mp3s and upload these from the app, in editor mode, on their phone. This is not very efficient.

Problems: I see a lot of Mac Catalyst stackoverflow problems with getting iOS/iPad code and firebase to work together. Mac Catalyst is not yet supported by Google's Firebase.

Thanks

1 Answers

FIXED

I have a set of steps that solves creating a Mac app to edit another firebase database. At the end you can zip up and send the app to another mac user to run.

1.Create a new XCode project - called here tryMacCatalyst.

2.Tick the box Mac and tap the enable button that comes up. Then run on the Mac to confirm. Then close the project to add PODS.

XCode settings

3.From the command line of the project do the usual to init a pod project.

pod init
  1. Edit the podfile to look just like this:

enter image description here

  1. Run pod install: enter image description here

  2. Open the xcworkspace in XCode, and run on 'My Mac' to test building of these libraries.

  3. Now copy in to the project the 'GoogleService-Info.plist' from the target firebase installation. it should look something like this:

enter image description here

It turns out that you can swap in-out any Google-Service-Info file here to point to any Firebase DB.

  1. Build the App. It will give an error:

Signing for "gRPC-C++-gRPCCertificates-Cpp" requires a development team. Select a development team in the Signing & Capabilities editor.

  1. So, in XCode hilight the PODS folder so it shows like below: And set the Team.

enter image description here

  1. Now add some swift code,FirebaseApp.configure to AppDelegate:

enter image description here

11.Add code to ViewController to test connection:Run and you should see in the log "firebase auth checked - no user""

import FirebaseAuth
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    
        if Auth.auth().currentUser == nil {
            print("firebase auth checked - no user")
        }else{
            print("firebase auth checked - we have a user")
        }
    }
}

12.Add code to ViewController to test connection to Firebase Auth:

import FirebaseAuth

class ViewController: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()
    
    if Auth.auth().currentUser == nil {
        print("firebase auth checked - no user")
        Auth.auth().signInAnonymously { (authResult, err) in
            
            if let err = err {
                print("Cannot login in anon - something bad happened ")
                print(err)
            }else{
                if let user = authResult?.user {
                    print(user.uid)
                }
            }
        }
    }else{
        print("firebase auth checked - we have a user")
    }
}

}

When you run this you will get an error:

An error occurred when accessing the keychain.

  1. To fix simply go to the XCode project / Signing and Capabilities / and add 'Keychain Sharing'.

Run again and it should work with the log showing something like:

gvMPr3Z7Aoh6tOA4lo1S3r9abcde

This is the anon userid. If you go to the Firebase console auth section this uid will be present. All firestore commands will now work. There is one final Step because if we try to Archive this it will fail.

  1. Archiving gives the error:

    ssl_transport_security.h:29:12: Did not find header 'x509.h' in framework 'openssl_grpc'

To fix this we use the well known answer given by zummenix on github: zummenix answer github link

The steps are given here:

  1. Create a mac sh file 'runBORINGSSLPatch.sh' and use the following (changing <YOUR_MAC_LOGON_NAME> and <PROJECT_NAME>):

         # This works
         # CD to <PROJECT_NAME> folder
         # 1. run using command line
         #  ./runBoringSSLPatch.sh
         # 2. then do archive - distribute directly to customers - Export
         # 3. Ctrl/C to stopscript
         #
         # script is at:
         # https://github.com/grpc/grpc/issues/20500
    
     while true; do
     sleep 0.1
     _boring_ssl=$(find /Users/<YOUR_MAC_LOGON_NAME>/Library/Developer/Xcode/DerivedData/<PROJECT_NAME>* \
         -name "BoringSSL-GRPC" | head -n1)
    
     cd "$_boring_ssl/openssl_grpc.framework" && ln -s Versions/Current/Headers Headers &&
         echo "Patched openssl_grpc"
    
     _grpc_core=$(find /Users/<YOUR_MAC_LOGON_NAME>/Library/Developer/Xcode/DerivedData/<PROJECT_NAME>* \
         -name "gRPC-Core" | head -n1)
    
     cd "$_grpc_core/grpc.framework" && ln -s Versions/Current/Headers Headers &&
         echo "Patched grpc"
     done
    
  2. Run this file using the command:

    ./runBoringSSLPatch.sh

  3. Archive again - and it should work. Now 'Distribute App', Developer ID, Export. Then send the folder to another user.

  4. CTRL-C the runBoringSSLPatch program.

Thanks

John Goodstadt

Related