Accessing MacOS native apis for Tauri Apps

I recently built an app using Tauri where I was trying to access a user's a contacts list using the native macos apis. My code worked in development but the app would crash when bundled and signed.

To make it work, you need to do two things:

  1. Add necessary attributes to Info.plist placed in the src-tauri directory
  2. Add the correct entitlements to your entitlements.plist file, also placed in the src-tauri directory.

To let Tauri know about the entitlements.plist file, I had to add it under the "entitlements" section of my tauri.config.json file. It looked something like this:

"macOS": {
  "entitlements": "./entitlements.mac.plist",
  "exceptionDomain": "",
  "frameworks": [],
  "providerShortName": null,
  "signingIdentity": null
},
macOS section under tauri > bundle section of tauri.config.json

My Info.plist looked like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>NSContactsUsageDescription</key>
  <string>Why your app needs contacts info</string>
</dict>
</plist>
Info.plist

My entitlements.plist looked like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.security.personal-information.addressbook</key>
    <true/>
  </dict>
</plist>
entitlements.plist

This is particular for accessing contact list but I imagine you need to do something similar for webcam, microphone, etc.

Happy building with Tauri!