xcodemacoscmakeapple-push-notifications

CMake Xcode generator - add capability "push notifications"


I tried to followup question CMake Xcode generator - add capability "hardened runtime" but instead of "Hardener Runtime" I need to automate enabling Push Notofication Capability from CMAKE... so I tried:

XCODE_ATTRIBUTE_ENABLE_PUSH_NOTIFICATIONS YES

also

XCODE_ATTRIBUTE_ENABLE_PUSH_NOTIFICATIONS TRUE

but nothing worked...

is there any known solution to this?

the relevant part of my CMakeLists.txt looks like:

set_target_properties(${TARGET_NAME} PROPERTIES
    MACOSX_BUNDLE TRUE

    # Build Info.plist the old way
    MACOSX_BUNDLE_GUI_IDENTIFIER                        "com.something.myAppName"
    MACOSX_BUNDLE_BUNDLE_NAME                           "myAppName"
    MACOSX_BUNDLE_BUNDLE_VERSION                        ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING                  ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE_INFO_PLIST                            "${CMAKE_CURRENT_SOURCE_DIR}/ios/Info.plist.in"
    #QT_IOS_LAUNCH_SCREEN                                "${CMAKE_CURRENT_SOURCE_DIR}/ios/LaunchScreen.storyboard"

    # New Xcode attributes for General tab
    # My convention for version numbering is public marketing version 1.2, Xcode build 1.2.3
    # Xcode now supports other formats (even though Apple documentation doesn't say so yet)
    XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER           ${MY_APP_REVERSE_DNS_IDENTIFIER}
    XCODE_ATTRIBUTE_PRODUCT_NAME                        ${MY_APP_PROJECT_NAME}
    XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION             ${PROJECT_VERSION}
    XCODE_ATTRIBUTE_MARKETING_VERSION                   ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME  "AppIcon"
    # XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY             2 # iPad only in my case

    XCODE_ATTRIBUTE_INFOPLIST_KEY_CFBundleDisplayName       ${MY_APP_PROJECT_NAME}
    # XCODE_ATTRIBUTE_INFOPLIST_KEY_LSApplicationCategoryType "public.app-category.mycategory" # Choose your own category

    # XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS "YES"

    XCODE_ATTRIBUTE_ENABLE_PUSH_NOTIFICATIONS           YES
    # XCODE_ATTRIBUTE_ENABLE_PUSH_NOTIFICATIONS         TRUE            # no difference
)

Thank you


Solution

  • correct way is to create .entitlements file which contains:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>aps-environment</key>
        <string>development</string>
    </dict>
    </plist>
    

    and then set it inside set_target_properties():

    XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/ios/<targetName>.entitlements"