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!

Hello edee1337 and Frameworks Engineer

Which flag and where we have to add this in our project? Could you please help me to fix this issue.

Actually I am working on Flutter project and need to integrate Rich Notification. For that I have created Notification Service Extension on Native side and using MoEngage SDK for Rich Notifications. After adding Extension it is showing the same issue mention above in most of files.

I checked a lot on StackOverflow and Apple forums but didn't get any solution.

Please help me to resolve this issue if you have any working solution or suggestion for the same.

Thanks.

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