e-sites / Natrium

A pre-build (Swift) script to alter your Xcode project at pre-build-time per environment, build configuration and target.
https://www.e-sites.nl
MIT License
146 stars 15 forks source link

Config different Capabilities based on environment #24

Open vinhlk opened 5 years ago

vinhlk commented 5 years ago

Hi is there a way to config Different Capabilities base on environment (Dev, Stagging, Production) (in my case is AppGroup) ?

Seem we should modify

plists:
    "NatriumExampleProject/Info.plist":
        CFBundleDisplayName:
            Staging: App_staging
            Production: App
    "NatriumExampleProject/App.entitlements":
        "aps-environment":
            "*":
                Debug: "development"
                Release: "production"

But what is the config for other capabilities? (AppGroup for example)?

basvankuijck commented 5 years ago

You could use xcconfig variables in your entitlements file, for instance:

<?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>com.apple.security.application-groups</key>
    <array>
        <string>$(APPGROUP1)</string>
        <string>$(APPGROUP2)</string>
    </array>
</dict>
</plist>

and then use this in .natrium.yml

xcconfig:
    APPGROUP1: "com.app.group1"
    APPGROUP2: "com.app.group2"

or create different entitlement files per configuration / environment and use the files setting in your .natrium.yml file

vinhlk commented 5 years ago

Thanks. How about extension entitlement? (PushNotificationExtension.entitlements) (in extension we also have entitlement). can we still use xcconfig?

basvankuijck commented 5 years ago

@vinhlk: Yes, works the same way

vinhlk commented 5 years ago

I have tried NotificationExtension. the 1st option xcconfig does not seem to work. (Also created scheme for pushnotification-dev, pushnotification-staging...)

basvankuijck commented 5 years ago

Another approach would be to use the files setting in your .natrium.yml file:


files:
    Path/To/NotificationExtensions.entitlements:
        Staging: Path/To/NotificationExtensions-staging.entitlements:
        Production: Path/To/NotificationExtensions-production.entitlements:

The only thing you need to do is create 2 seperate entitlements files for each environment

vinhlk commented 5 years ago

I still have problem config natrium with notification extension. I have set value for notification extension 'sinfo.plist (withbundle ID and Display name ) for different environment and successfully generate Bundle Identifier for notification extension. But in my build setting (for notification extension target, the Product Bundle Identifier value never change. Do you have a sample natrium that use notification extension for different environment?

vinhlk commented 5 years ago

Hi @basvankuijck I made it work by using multiple file for notification extension entitlement. i have tried xcconfig and "RichPushNotificationExtension/NotificationExtension.entitlements": "com.apple.security.application-groups": "#{AppGroup}" but no luck. Hope there is an update support these config instead of multiple file

basvankuijck commented 5 years ago

The "problem" is that it only changes the xcconfig for the target that initiates the build (e.g. NatriumExampleProject) and not any target dependencies (e.g. RichPushNotificationExtension).

I'll put it on the todo list so you can change the settings of any dependency target