I have recently started working on my first macOS App Focus Recorder.
Apple has done a great job to unify the development process of iOS and macOS. But there are still some differences between iOS and macOS that developers need to know about. There are also many pitfalls surfacing if the macOS app is sandboxed. One another drawback when developing apps for macOS is the lack of documentation for macOS development, in comparision to iOS development.
This blog post is used as a notebook for me to jot down problems and solutions during the development of Focus Recorder
How to solve no teamID issue when signing a macOS app?
Problem
I’m using fastlane to distribute the app to Testflight. But I have recently the No “teamID” issue:
Error Domain=IDEFoundationErrorDomain Code=1 "No "teamID" specified and no team ID found in the archive" UserInfo={NSLocalizedDescription=No "teamID" specified and no team ID found in the archive}
Solution
Create a manual provisioning profile and set it manually in fastlane script
build_mac_app(
scheme: XCODE_SCHEME,
export_method: "app-store",
export_options: {
provisioningProfiles: {
"app.antran.focusrecorder" => "app.antran.focusrecorder AppStore",
}
}
)
How to run UI Tests for a macOS app?
Problem
I’m trying to run a UItest for my app, but encounter this issue:
FocusRecorder (6842) encountered an error (Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at xxx/Logs/Test/Test-FocusRecorder-Dev-2023.04.18_00-15-09-+0700.xcresult. (Underlying Error: The bundle “FocusRecorderTests” couldn’t be loaded. The bundle couldn’t be loaded. Try reinstalling the bundle. dlopen(xxx/Build/Products/Debug/FocusRecorder.app/Contents/PlugIns/FocusRecorderTests.xctest/Contents/MacOS/FocusRecorderTests, 0x0109): tried: '/Users/antran/Library/Developer/Xcode/DerivedData/FocusRecorder-dpznqbgvobkvlmdsgqdydhmkaqgc/Build/Products/Debug/FocusRecorderTests' (no such file), '/Applications/Xcode-14.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/FocusRecorderTests' (no such file), 'xxx/Build/Products/Debug/FocusRecorder.app/Contents/PlugIns/FocusRecorderTests.xctest/Contents/MacOS/FocusRecorderTests' (code signature in <DCAF3C4D-E87A-3ECA-9BF7-DCEC2E13D6B9> 'xxx/Build/Products/Debug/FocusRecorder.app/Contents/PlugIns/FocusRecorderTests.xctest/Contents/MacOS/FocusRecorderTests' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))))
Solution
There is a long discussion about running macOS UI Tests with Xcode 14 in Swift Forums
We need to disable the code signing to ensure that the tests can start
xcodebuild test \
-project FocusRecorder.xcodeproj \
-scheme "FocusRecorder-Dev" \
-destination "platform=macOS" \
CODE_SIGN_STYLE="Manual" \
CODE_SIGN_IDENTITY="" \
DEVELOPMENT_TEAM="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO