Reputation: 813
I created a macOS app that can run in foreground (NSApplicationActivationPolicyRegular
) and in background (NSApplicationActivationPolicyAccessory
) and can be launched by an Helper (Login Item) and run in background.
I use XCode 15.3 (15E204a) on macOS 14.2.1 on a MacBook Pro 16", 2019, 2,3 GHz Intel Core i9 8 core.
I archive my app, I notarize it for direct distribution then I save it to the /Applications folder. Then I delete my Debug app from …/Xcode/DerivedData/MyApp-dal…xu/Build/Products/Debug so I am sure I have one only copy of my app on the disk.
I firstly launch my app as NSApplicationActivationPolicyRegular
then I select my menu item "Set the app as Login Item". So I call
SMAppService *service = [SMAppService loginItemServiceWithIdentifier:@"com.mydomain.Helper"];
I get a
service.status == SMAppServiceStatusNotFound
So I am stuck. I notice that my app doesn't show up in the System Preferences/Login Items/ "Allow Background" list. So on Terminal I run the command
sudo sfltool resetbtm
Now the "Allow Background" apps list is empty. Then I reboot.
All the apps listed in "Allow Background" list reappear and are all turned "on". I turn them back off.
My app is on the list too (turned "on" too). I leave it on.
Now I can launch my app as NSApplicationActivationPolicyRegular
, select again my menu item "Set the app as Login Item" and call
SMAppService *service = [SMAppService loginItemServiceWithIdentifier:@"com.domain.Helper"];
Now I get a
service.status == SMAppServiceStatusEnabled
so I install the NSStatusItem
and switch to background (NSApplicationActivationPolicyAccessory
).
I can logout and login and my app gets properly launched by the Helper and run in background.
Everything works well.
I guess I miss something,
because I think this is not the way to distribute my app to the customers. I can't ask my customers to run the Terminal command sudo sfltool resetbtm
, reboot then turn back "off" all the unwanted apps from the "Allow Background" list then turn my app "on".
Furthermore, if I delete my app, it disappears from the "Allow Background" apps list, then if I copy it back to the /Applications
folder, it doesn't show up yet in the "Allow Background" apps list. I have to invoke again the sudo sfltool resetbtm
Terminal command, reboot… to see it in that list.
I tried on 3 machines with macOS 14.2.1. Same result.
I have read several articles and posts about NSApplicationActivationPolicyAccessory
, SMAppService
, but I didn't find my case. The Info.plist file of the Helper properly contains
<key>LSBackgroundOnly</key><true/>
<key>LSUIElement</key><true/>
• What do I miss?
• Why my app doesn't show up in the "Allow Background" apps list when I simply copy it within the /Applications folder?
Upvotes: 1
Views: 168