0

1. What we want to achieve

Install a pre-configured cordova app using fb cordova plugin ( cordova-plugin-facebook4 - https://github.com/jeduan/cordova-plugin-facebook4 )

2. Problem

The problem derives from the "pre-configured" part. As a default, the plugin required to being install passing it some configurations like APP_NAME / APP_ID values, as documentation at < https://ionicframework.com/docs/native/facebook > specified.

This is a problem for us because our application creation flow process is based mainly onto the Cordova's configuration config.xml where clearly all plugins are listed.

3. Question

Our need is to be able to pass some configuration directly inside the config.xml file, like for other plugins here below shown:

<plugin name="cordova-plugin-camera" spec="2.4.1">
    <variable name="CAMERA_USAGE_DESCRIPTION" value="Allow the app to use your camera" />
    <variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="Allow the app to access your photos" />
</plugin>

In the previous lines, variables for cordova-plugin-camera is the way to configure the plugin.

4. Alternative solutions not adopted

Reading around, some solution required to change plugin.xml file of facebook-plugin.

The problem of this solution is the cost for the forked plugin maintenance.

5. Question-based on 4.

Avoiding to fork plugin for configuration setting purpose, can be HOOKS approach usefull? I mean, can we replace "preference" tag inside plugin.xml at some build / prepare / plugin install time as wrote in the second answer at the following link < Cordova Facebook plugin : missing variables APP_ID, APP_NAME > ?

thanks for reading!!

Simone Campagna
  • 1,130
  • 1
  • 10
  • 19

1 Answers1

1

You can specify the APP_ID and APP_NAME in the config XML as following:-

Under Android Platforms:-

<config-file parent="/resources" target="./res/values/strings.xml">
    <string name="fb_app_id">574355309670137</string>
    <string name="fb_app_name">HUB App</string>
</config-file>

And outside the platform and at the bottom(when installed fb plugin) it would be defined as below:-

<plugin name="cordova-plugin-facebook4" spec="^3.1.0">
    <variable name="APP_ID" value="574355309670137" />
    <variable name="APP_NAME" value="HUB App" />
</plugin>

Please let me know if you have any questions.

  • Sure!!! Before you wrote, i'm trying the second part of your answer (plugin variables), just now starting build :) A question in the meanwhile: why the first part for android ? is mandatory ? "fb_app_id" and "fb_app_name" are described / default string name required by fb cordova plugin ? Thanks – Simone Campagna May 29 '19 at 10:57
  • @SimoneCampagna In Android, if we do not add that part it does not recognize the fb app id and gives an error. This is researched by me and the implementation came once the research was done. I have an app working when I add these variables. – Abhishek Rlogical May 29 '19 at 11:43
  • @SimoneCampagna Any updates on this? Did this solution worked for you? – Abhishek Rlogical Jun 03 '19 at 07:02
  • Hi Abhishek, and sorry for delay. – Simone Campagna Jun 04 '19 at 14:07
  • Your solution is OK even if i didn't use the first part (Android requirement for fb_app_id and fb_app_name). We're currently using cordova-plugin-facebook4 4.2.1 under cordova 7.1.0. Simone – Simone Campagna Jun 04 '19 at 14:26