Search code examples
iosnativescriptpodfileshare-extension

Modify Podfile in Nativescript application


I've added a share extension to my Nativescript app, and this extension needs a Pod.

So I need to modify the Podfile of the Nativescript app to target my share extension too with the required Pod, something like this:

target :MyApp do
    platform :ios, '8.0'
    use_frameworks!

    pod 'AFNetworking', '~> 2.0'
    pod '...'
end

target :MyExtension do
    use_frameworks!

    pod 'AFNetworking', '~> 2.0'
end

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        if target.name.start_with? "Pods-MyExtension"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
            end
        end
    end
end

The problem here is that every time I run the project, the Podfile is overwritten by Nativescript.

So, there's a way to "block" the Podfile for prevent Nativescript overrides it, or maybe a "hook" for adding custom content to the Podfile after Nativescript Podfile generation?

How can I proceed with this?

Thanks.


Solution

  • In order to modify the Podfile that is generated in the platforms folder at build time you can add a Podfile in the App_Resources/iOS folder.

    The Podfile in the App_Resources/iOS folder will be merged with the Podfile that is generated in the platforms folder.