Categories
SwiftUI

Xcode 12.5 start force Action target must set APPLICATION_EXTENSION_API_ONLY to true

From Xcode 12.5 start Apple force Action target must set APPLICATION_EXTENSION_API_ONLY to true. If you didn’t set it, you will get an error “Application extensions and any libraries they link to must be built with the `APPLICATION_EXTENSION_API_ONLY` build setting set to YES.“.

But normally we share a lot of codes between App targets and Action targets. So codes in Action target will contain some codes that don’t obey extension-only API requests. Like UIApplication.shared.open, UIApplication.shared.keyWindow and so on.

So we can warp these codes using #if !ACTION_EXTENSION, like this:

#if !ACTION_EXTENSION
    //codes that don't obey extension-only API requests
#else
    //normal codes 
#endif 

4 replies on “Xcode 12.5 start force Action target must set APPLICATION_EXTENSION_API_ONLY to true”

hi tinyfool,tks your article, but I still don‘t know how to solve this problem. ACTION_EXTENSION is a system macro or custom? how to conditionally open or close, usually build one framework for all dependency

Do you have a target is action type?
Open your source code file cause error, click menu View->inspectors-File, check the inspector the source file must in some action type target.

When you code in action type target, ACTION_EXTENSION will be set automatically.

hi tinyfool, thanks a lot, I know your meanings, but My project only has a share extension, Does it also has SHARE_EXTENSION just like ACTION_EXTENSION?

Hi Kingnight,

You can look at your targets’ “Build settings”, select “All”, “Levels”, Other Swift Flags.

You may find -D ACTION_EXTENSION.

I can’t sure share extension must include ACTION_EXTENSION, but may it introduce by some mistake operation?

Leave a Reply

Your email address will not be published. Required fields are marked *