Flag to avoid "shared is unavailable in application extensions" error?

Hello,

I am trying to get my camera app to launch from the Lock Screen, and see that calls to UIApplication.shared are not allowed. In my app, I have:

UIApplication.shared.isIdleTimerDisabled = true

Which is causing this compile time error:

'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead

I do not believe there is a view controller based solution for this. Is there a flag I can wrap around the call so that the compiler knows it won't be used during an application extension?

Thank you!

Answered by Frameworks Engineer in 805766022

Hello edee1337,

One option is to add a custom compile flag to either your app or your Capture Extension target's build settings, and then reference that in the code.

Accepted Answer

Hello edee1337,

One option is to add a custom compile flag to either your app or your Capture Extension target's build settings, and then reference that in the code.

Thank you, I believe that's what I was looking for!

Flag to avoid "shared is unavailable in application extensions" error?
 
 
Q