How to call SMLoginItemSetEnabled in Mac Catalyst project ?

How to call SMLoginItemSetEnabled in Mac Catalyst project ?

Our application needs to run automatically at Macos system login. We developed the MacOS app using Mac Catalyst. Normally, MAC projects do this by calling SMLoginItemSetEnabled, but SMLoginItemSetEnabled cannot be called in the MAC Catalyst project.

In the <ServiceManagement/ServiceManagement.h> are defined as follows:

#if !TARGET_OS_IPHONE #include <Security/Authorization.h> #include <ServiceManagement/SMLoginItem.h> #else // !TARGET_OS_IPHONE

The macro “TARGET_OS_IPHONE” is 1 in Mac Catalyst project.

Does anyone know how to resove this problem? Thank you!

Answered by DTS Engineer in 686672022

You are correct that SMLoginItemSetEnabled is not supported under Mac Catalyst. This is less than ideal and I encourage you to file a bug requesting that it be made available.

Please post your bug number, just for the record.

As to workarounds, from a packaging perspective Mac Catalyst apps are Mac apps, so you can package a Serivce Management login item in your app just like you would with any other Mac app. The only sticking point here is calling SMLoginItemSetEnabled itself.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

You are correct that SMLoginItemSetEnabled is not supported under Mac Catalyst. This is less than ideal and I encourage you to file a bug requesting that it be made available.

Please post your bug number, just for the record.

As to workarounds, from a packaging perspective Mac Catalyst apps are Mac apps, so you can package a Serivce Management login item in your app just like you would with any other Mac app. The only sticking point here is calling SMLoginItemSetEnabled itself.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

if I were to modify the file in XX/Library/LaunchAgents with code, I would need to request read/write access to the file outside of the sandbox

You are correct that SMLoginItemSetEnabled is the only supported approach for persistent code execution on the Mac App Store.

Beyond that, I see that you’re in touch with one of my colleagues about this and I’m going to let them answer officially.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to call SMLoginItemSetEnabled in Mac Catalyst project ?
 
 
Q