diff --git a/.changeset/config.json b/.changeset/config.json index 968549ac..325de4c3 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -13,7 +13,8 @@ "@capacitor-firebase/authentication", "@capacitor-firebase/crashlytics", "@capacitor-firebase/messaging", - "@capacitor-firebase/performance" + "@capacitor-firebase/performance", + "@capacitor-firebase/remote-config" ] ], "linked": [], diff --git a/.changeset/happy-humans-watch.md b/.changeset/happy-humans-watch.md new file mode 100644 index 00000000..bf59d70c --- /dev/null +++ b/.changeset/happy-humans-watch.md @@ -0,0 +1,5 @@ +--- +"@capacitor-firebase/remote-config": minor +--- + +Initial release 🎉 diff --git a/README.md b/README.md index efe58e55..576187f5 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Click on the name of the desired plugin under the [`Plugins`](#plugins) section | [Crashlytics](./packages/crashlytics) | `@capacitor-firebase/crashlytics` | [![npm badge](https://img.shields.io/npm/v/@capacitor-firebase/crashlytics?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/crashlytics) | [![npm downloads](https://img.shields.io/npm/dw/@capacitor-firebase/crashlytics?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/crashlytics) | | [Cloud Messaging](./packages/messaging) | `@capacitor-firebase/messaging` | [![npm badge](https://img.shields.io/npm/v/@capacitor-firebase/messaging?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/messaging) | [![npm downloads](https://img.shields.io/npm/dw/@capacitor-firebase/messaging?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/messaging) | | [Performance Monitoring](./packages/performance) | `@capacitor-firebase/performance` | [![npm badge](https://img.shields.io/npm/v/@capacitor-firebase/performance?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/performance) | [![npm downloads](https://img.shields.io/npm/dw/@capacitor-firebase/performance?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/performance) | +| [Remote Config](./packages/remote-config) | `@capacitor-firebase/remote-config` | [![npm badge](https://img.shields.io/npm/v/@capacitor-firebase/remote-config?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/remote-config) | [![npm downloads](https://img.shields.io/npm/dw/@capacitor-firebase/remote-config?style=flat-square)](https://www.npmjs.com/package/@capacitor-firebase/remote-config) | ## Changelogs diff --git a/package-lock.json b/package-lock.json index 1231c16e..6461fb1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,6 +86,10 @@ "resolved": "packages/performance", "link": true }, + "node_modules/@capacitor-firebase/remote-config": { + "resolved": "packages/remote-config", + "link": true + }, "node_modules/@capacitor/android": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-4.0.1.tgz", @@ -6903,6 +6907,42 @@ "@capacitor/core": "^4.0.0", "firebase": "^9.0.0" } + }, + "packages/remote-config": { + "version": "1.2.0", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/capawesome-team/" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/capawesome" + } + ], + "license": "Apache-2.0", + "devDependencies": { + "@capacitor/android": "4.0.1", + "@capacitor/cli": "4.0.1", + "@capacitor/core": "4.0.1", + "@capacitor/docgen": "0.2.0", + "@capacitor/ios": "4.0.1", + "@ionic/eslint-config": "0.3.0", + "@ionic/prettier-config": "1.0.1", + "@ionic/swiftlint-config": "1.1.2", + "eslint": "7.32.0", + "firebase": "9.6.4", + "prettier": "2.3.2", + "prettier-plugin-java": "1.0.2", + "rimraf": "3.0.2", + "rollup": "2.77.2", + "swiftlint": "1.0.1", + "typescript": "4.1.5" + }, + "peerDependencies": { + "@capacitor/core": "^4.0.0", + "firebase": "^9.0.0" + } } }, "dependencies": { @@ -7088,6 +7128,27 @@ "typescript": "4.1.5" } }, + "@capacitor-firebase/remote-config": { + "version": "file:packages/remote-config", + "requires": { + "@capacitor/android": "4.0.1", + "@capacitor/cli": "4.0.1", + "@capacitor/core": "4.0.1", + "@capacitor/docgen": "0.2.0", + "@capacitor/ios": "4.0.1", + "@ionic/eslint-config": "0.3.0", + "@ionic/prettier-config": "1.0.1", + "@ionic/swiftlint-config": "1.1.2", + "eslint": "7.32.0", + "firebase": "9.6.4", + "prettier": "2.3.2", + "prettier-plugin-java": "1.0.2", + "rimraf": "3.0.2", + "rollup": "2.77.2", + "swiftlint": "1.0.1", + "typescript": "4.1.5" + } + }, "@capacitor/android": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-4.0.1.tgz", diff --git a/packages/remote-config/.eslintignore b/packages/remote-config/.eslintignore new file mode 100644 index 00000000..9d0b71a3 --- /dev/null +++ b/packages/remote-config/.eslintignore @@ -0,0 +1,2 @@ +build +dist diff --git a/packages/remote-config/.gitignore b/packages/remote-config/.gitignore new file mode 100644 index 00000000..70ccbf71 --- /dev/null +++ b/packages/remote-config/.gitignore @@ -0,0 +1,61 @@ +# node files +dist +node_modules + +# iOS files +Pods +Podfile.lock +Build +xcuserdata + +# macOS files +.DS_Store + + + +# Based on Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore + +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin +gen +out + +# Gradle files +.gradle +build + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation + +# Android Studio captures folder +captures + +# IntelliJ +*.iml +.idea + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild diff --git a/packages/remote-config/.npmrc b/packages/remote-config/.npmrc new file mode 100644 index 00000000..cffe8cde --- /dev/null +++ b/packages/remote-config/.npmrc @@ -0,0 +1 @@ +save-exact=true diff --git a/packages/remote-config/.prettierignore b/packages/remote-config/.prettierignore new file mode 100644 index 00000000..9d0b71a3 --- /dev/null +++ b/packages/remote-config/.prettierignore @@ -0,0 +1,2 @@ +build +dist diff --git a/packages/remote-config/BREAKING.md b/packages/remote-config/BREAKING.md new file mode 100644 index 00000000..129fa2f0 --- /dev/null +++ b/packages/remote-config/BREAKING.md @@ -0,0 +1,3 @@ +# Breaking Changes + +This is a comprehensive list of the breaking changes introduced in the major version releases of Capacitor Firebase Remote Config plugin. diff --git a/packages/remote-config/CHANGELOG.md b/packages/remote-config/CHANGELOG.md new file mode 100644 index 00000000..825c32f0 --- /dev/null +++ b/packages/remote-config/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/remote-config/CapacitorFirebaseRemoteConfig.podspec b/packages/remote-config/CapacitorFirebaseRemoteConfig.podspec new file mode 100644 index 00000000..87d8865b --- /dev/null +++ b/packages/remote-config/CapacitorFirebaseRemoteConfig.podspec @@ -0,0 +1,19 @@ +require 'json' + +package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) + +Pod::Spec.new do |s| + s.name = 'CapacitorFirebaseRemoteConfig' + s.version = package['version'] + s.summary = package['description'] + s.license = package['license'] + s.homepage = package['repository']['url'] + s.author = package['author'] + s.source = { :git => package['repository']['url'], :tag => s.version.to_s } + s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' + s.ios.deployment_target = '13.0' + s.dependency 'Capacitor' + s.dependency 'Firebase/RemoteConfig', '9.1.0' + s.swift_version = '5.1' + s.static_framework = true +end diff --git a/packages/remote-config/LICENSE b/packages/remote-config/LICENSE new file mode 100644 index 00000000..8f403f83 --- /dev/null +++ b/packages/remote-config/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 Robin Genz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/remote-config/README.md b/packages/remote-config/README.md new file mode 100644 index 00000000..63ad2eb4 --- /dev/null +++ b/packages/remote-config/README.md @@ -0,0 +1,297 @@ +# @capacitor-firebase/remote-config + +⚡️ Capacitor plugin for Firebase Remote Config. + +## Installation + +```bash +npm install @capacitor-firebase/remote-config firebase +npx cap sync +``` + +Add Firebase to your project if you haven't already ([Android](https://firebase.google.com/docs/android/setup) / [iOS](https://firebase.google.com/docs/ios/setup) / [Web](https://firebase.google.com/docs/web/setup)). + +### Android + +Google Analytics is required for the [conditional targeting of app instances](https://firebase.google.com/docs/remote-config/parameters#conditions_rules_and_conditional_values) to user properties and audiences. Make sure that you install the [Capacitor Firebase Analytics](/packages/analytics) plugin in your project. + +#### Variables + +This plugin will use the following project variables (defined in your app’s `variables.gradle` file): + +- `$firebaseConfigVersion` version of `com.google.firebase:firebase-config` (default: `21.2.0`) + +## Configuration + +No configuration required for this plugin. + +## Demo + +A working example can be found here: [robingenz/capacitor-firebase-plugin-demo](https://github.com/robingenz/capacitor-firebase-plugin-demo) + +## Usage + +```typescript +import { FirebaseRemoteConfig } from '@capacitor-firebase/remote-config'; + +const activate = async () => { + await FirebaseRemoteConfig.activate(); +}; + +const fetchAndActivate = async () => { + await FirebaseRemoteConfig.fetchAndActivate(); +}; + +const fetchConfig = async () => { + await FirebaseRemoteConfig.fetchConfig({ + minimumFetchIntervalInSeconds: 1200, + }); +}; + +const getBoolean = async () => { + const { value } = await FirebaseRemoteConfig.getBoolean({ + key: 'is_sale', + }); + return value; +}; + +const getNumber = async () => { + const { value } = await FirebaseRemoteConfig.getNumber({ + key: 'upcoming_maintenance', + }); + return value; +}; + +const getString = async () => { + const { value } = await FirebaseRemoteConfig.getString({ + key: 'license_key', + }); + return value; +}; +``` + +## API + + + +* [`activate()`](#activate) +* [`fetchAndActivate()`](#fetchandactivate) +* [`fetchConfig(...)`](#fetchconfig) +* [`getBoolean(...)`](#getboolean) +* [`getNumber(...)`](#getnumber) +* [`getString(...)`](#getstring) +* [`setMinimumFetchInterval(...)`](#setminimumfetchinterval) +* [Interfaces](#interfaces) +* [Type Aliases](#type-aliases) +* [Enums](#enums) + + + + + + +### activate() + +```typescript +activate() => Promise +``` + +Make the last fetched configuration available to the getters. + +**Since:** 1.3.0 + +-------------------- + + +### fetchAndActivate() + +```typescript +fetchAndActivate() => Promise +``` + +Perform fetch and activate operations. + +**Since:** 1.3.0 + +-------------------- + + +### fetchConfig(...) + +```typescript +fetchConfig(options?: FetchConfigOptions | undefined) => Promise +``` + +Fetch and cache configuration from the Remote Config service. + +| Param | Type | +| ------------- | ----------------------------------------------------------------- | +| **`options`** | FetchConfigOptions | + +**Since:** 1.3.0 + +-------------------- + + +### getBoolean(...) + +```typescript +getBoolean(options: GetBooleanOptions) => Promise +``` + +Get the value for the given key as a boolean. + +| Param | Type | +| ------------- | ------------------------------------------------- | +| **`options`** | GetOptions | + +**Returns:** Promise<GetBooleanResult> + +**Since:** 1.3.0 + +-------------------- + + +### getNumber(...) + +```typescript +getNumber(options: GetNumberOptions) => Promise +``` + +Get the value for the given key as a number. + +| Param | Type | +| ------------- | ------------------------------------------------- | +| **`options`** | GetOptions | + +**Returns:** Promise<GetNumberResult> + +**Since:** 1.3.0 + +-------------------- + + +### getString(...) + +```typescript +getString(options: GetStringOptions) => Promise +``` + +Get the value for the given key as a string. + +| Param | Type | +| ------------- | ------------------------------------------------- | +| **`options`** | GetOptions | + +**Returns:** Promise<GetStringResult> + +**Since:** 1.3.0 + +-------------------- + + +### setMinimumFetchInterval(...) + +```typescript +setMinimumFetchInterval(options: SetMinimumFetchIntervalOptions) => Promise +``` + +Set the minimum fetch interval. + +Only available on Web. + +| Param | Type | +| ------------- | ----------------------------------------------------------------------------------------- | +| **`options`** | SetMinimumFetchIntervalOptions | + +**Since:** 1.3.0 + +-------------------- + + +### Interfaces + + +#### FetchConfigOptions + +| Prop | Type | Description | Default | Since | +| ----------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ----- | +| **`minimumFetchIntervalInSeconds`** | number | Define the maximum age in seconds of an entry in the config cache before it is considered stale. During development, it's recommended to set a relatively low minimum fetch interval. Only available on Android and iOS. | 43200 | 1.3.0 | + + +#### GetBooleanResult + +| Prop | Type | Description | Since | +| ------------ | --------------------------------------------------------- | ---------------------------------------------------------------------------------- | ----- | +| **`value`** | boolean | The value for the given key as a boolean. | 1.3.0 | +| **`source`** | GetValueSource | Indicates at which source this value came from. Only available on Android and iOS. | 1.3.0 | + + +#### GetOptions + +| Prop | Type | Description | Since | +| --------- | ------------------- | ---------------------------- | ----- | +| **`key`** | string | The key of the value to get. | 1.3.0 | + + +#### GetNumberResult + +| Prop | Type | Description | Since | +| ------------ | --------------------------------------------------------- | ---------------------------------------------------------------------------------- | ----- | +| **`value`** | number | The value for the given key as a number. | 1.3.0 | +| **`source`** | GetValueSource | Indicates at which source this value came from. Only available on Android and iOS. | 1.3.0 | + + +#### GetStringResult + +| Prop | Type | Description | Since | +| ------------ | --------------------------------------------------------- | ---------------------------------------------------------------------------------- | ----- | +| **`value`** | string | The value for the given key as a string. | 1.3.0 | +| **`source`** | GetValueSource | Indicates at which source this value came from. Only available on Android and iOS. | 1.3.0 | + + +#### SetMinimumFetchIntervalOptions + +| Prop | Type | Description | Default | Since | +| ----------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | +| **`minimumFetchIntervalInSeconds`** | number | Define the maximum age in seconds of an entry in the config cache before it is considered stale. During development, it's recommended to set a relatively low minimum fetch interval. | 43200 | 1.3.0 | + + +### Type Aliases + + +#### GetBooleanOptions + +GetOptions + + +#### GetNumberOptions + +GetOptions + + +#### GetStringOptions + +GetOptions + + +### Enums + + +#### GetValueSource + +| Members | Value | Description | Since | +| ------------- | -------------- | --------------------------------------------------------------------------------------- | ----- | +| **`Static`** | 0 | Indicates that the value returned is the static default value. | 1.3.0 | +| **`Default`** | 1 | Indicates that the value returned was retrieved from the defaults set by the client. | 1.3.0 | +| **`Remote`** | 2 | Indicates that the value returned was retrieved from the Firebase Remote Config Server. | 1.3.0 | + + + +## Changelog + +See [CHANGELOG.md](/packages/remote-config/CHANGELOG.md). + +## License + +See [LICENSE](/packages/remote-config/LICENSE). diff --git a/packages/remote-config/android/.gitignore b/packages/remote-config/android/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/packages/remote-config/android/.gitignore @@ -0,0 +1 @@ +/build diff --git a/packages/remote-config/android/build.gradle b/packages/remote-config/android/build.gradle new file mode 100644 index 00000000..d628c61f --- /dev/null +++ b/packages/remote-config/android/build.gradle @@ -0,0 +1,59 @@ +ext { + junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2' + androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2' + androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3' + androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0' + firebaseConfigVersion = project.hasProperty('firebaseConfigVersion') ? rootProject.ext.firebaseConfigVersion : '21.2.0' +} + +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:7.2.1' + } +} + +apply plugin: 'com.android.library' + +android { + compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32 + defaultConfig { + minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22 + targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + lintOptions { + abortOnError false + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } +} + +repositories { + google() + mavenCentral() +} + + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':capacitor-android') + implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" + implementation "com.google.firebase:firebase-config:$firebaseConfigVersion" + testImplementation "junit:junit:$junitVersion" + androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" + androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" +} diff --git a/packages/remote-config/android/gradle.properties b/packages/remote-config/android/gradle.properties new file mode 100644 index 00000000..0566c221 --- /dev/null +++ b/packages/remote-config/android/gradle.properties @@ -0,0 +1,24 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true + +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true diff --git a/packages/remote-config/android/gradle/wrapper/gradle-wrapper.jar b/packages/remote-config/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..41d9927a Binary files /dev/null and b/packages/remote-config/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/packages/remote-config/android/gradle/wrapper/gradle-wrapper.properties b/packages/remote-config/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..92f06b50 --- /dev/null +++ b/packages/remote-config/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/remote-config/android/gradlew b/packages/remote-config/android/gradlew new file mode 100755 index 00000000..1b6c7873 --- /dev/null +++ b/packages/remote-config/android/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/packages/remote-config/android/gradlew.bat b/packages/remote-config/android/gradlew.bat new file mode 100644 index 00000000..107acd32 --- /dev/null +++ b/packages/remote-config/android/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/packages/remote-config/android/proguard-rules.pro b/packages/remote-config/android/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/packages/remote-config/android/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/packages/remote-config/android/settings.gradle b/packages/remote-config/android/settings.gradle new file mode 100644 index 00000000..9d983e09 --- /dev/null +++ b/packages/remote-config/android/settings.gradle @@ -0,0 +1,2 @@ +include ':capacitor-android' +project(':capacitor-android').projectDir = new File('../../../node_modules/@capacitor/android/capacitor') \ No newline at end of file diff --git a/packages/remote-config/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java b/packages/remote-config/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java new file mode 100644 index 00000000..58020e16 --- /dev/null +++ b/packages/remote-config/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.getcapacitor.android; + +import static org.junit.Assert.*; + +import android.content.Context; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.getcapacitor.android", appContext.getPackageName()); + } +} diff --git a/packages/remote-config/android/src/main/AndroidManifest.xml b/packages/remote-config/android/src/main/AndroidManifest.xml new file mode 100644 index 00000000..ae61dae7 --- /dev/null +++ b/packages/remote-config/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/ActivateResultCallback.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/ActivateResultCallback.java new file mode 100644 index 00000000..e21404fe --- /dev/null +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/ActivateResultCallback.java @@ -0,0 +1,6 @@ +package io.capawesome.capacitorjs.plugins.firebase.remoteconfig; + +public interface ActivateResultCallback { + void success(boolean success); + void error(String message); +} diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FetchConfigResultCallback.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FetchConfigResultCallback.java new file mode 100644 index 00000000..502d02e1 --- /dev/null +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FetchConfigResultCallback.java @@ -0,0 +1,6 @@ +package io.capawesome.capacitorjs.plugins.firebase.remoteconfig; + +public interface FetchConfigResultCallback { + void success(); + void error(String message); +} diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java new file mode 100644 index 00000000..0959b918 --- /dev/null +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java @@ -0,0 +1,76 @@ +package io.capawesome.capacitorjs.plugins.firebase.remoteconfig; + +import android.util.Log; +import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue; + +public class FirebaseRemoteConfig { + + private final com.google.firebase.remoteconfig.FirebaseRemoteConfig remoteConfigInstance; + + public FirebaseRemoteConfig() { + this.remoteConfigInstance = com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance(); + } + + public void activate(final ActivateResultCallback resultCallback) { + remoteConfigInstance + .activate() + .addOnSuccessListener( + result -> { + resultCallback.success(result.booleanValue()); + } + ) + .addOnFailureListener( + exception -> { + Log.w(FirebaseRemoteConfigPlugin.TAG, "Activate config failed.", exception); + resultCallback.error(exception.getLocalizedMessage()); + } + ); + } + + public void fetchAndActivate(final ActivateResultCallback resultCallback) { + remoteConfigInstance + .fetchAndActivate() + .addOnSuccessListener( + result -> { + resultCallback.success(result.booleanValue()); + } + ) + .addOnFailureListener( + exception -> { + Log.w(FirebaseRemoteConfigPlugin.TAG, "Fetch and activate config failed.", exception); + resultCallback.error(exception.getLocalizedMessage()); + } + ); + } + + public void fetchConfig(long minimumFetchIntervalInSeconds, final FetchConfigResultCallback resultCallback) { + remoteConfigInstance + .fetch(minimumFetchIntervalInSeconds) + .addOnSuccessListener( + result -> { + resultCallback.success(); + } + ) + .addOnFailureListener( + exception -> { + Log.w(FirebaseRemoteConfigPlugin.TAG, "Fetch config failed.", exception); + resultCallback.error(exception.getLocalizedMessage()); + } + ); + } + + public GetValueResult getBoolean(String key) { + FirebaseRemoteConfigValue value = remoteConfigInstance.getValue(key); + return new GetValueResult(value.asBoolean(), value.getSource()); + } + + public GetValueResult getNumber(String key) { + FirebaseRemoteConfigValue value = remoteConfigInstance.getValue(key); + return new GetValueResult(value.asDouble(), value.getSource()); + } + + public GetValueResult getString(String key) { + FirebaseRemoteConfigValue value = remoteConfigInstance.getValue(key); + return new GetValueResult(value.asString(), value.getSource()); + } +} diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java new file mode 100644 index 00000000..90251b32 --- /dev/null +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java @@ -0,0 +1,139 @@ +package io.capawesome.capacitorjs.plugins.firebase.remoteconfig; + +import com.getcapacitor.JSObject; +import com.getcapacitor.Plugin; +import com.getcapacitor.PluginCall; +import com.getcapacitor.PluginMethod; +import com.getcapacitor.annotation.CapacitorPlugin; + +@CapacitorPlugin(name = "FirebaseRemoteConfig") +public class FirebaseRemoteConfigPlugin extends Plugin { + + public static final String TAG = "FirebaseRemoteConfig"; + public static final String ERROR_KEY_MISSING = "key must be provided."; + private FirebaseRemoteConfig implementation = new FirebaseRemoteConfig(); + + @PluginMethod + public void activate(PluginCall call) { + try { + implementation.activate( + new ActivateResultCallback() { + @Override + public void success(boolean success) { + call.resolve(); + } + + @Override + public void error(String message) { + call.reject(message); + } + } + ); + } catch (Exception ex) { + call.reject(ex.getLocalizedMessage()); + } + } + + @PluginMethod + public void fetchAndActivate(PluginCall call) { + try { + implementation.fetchAndActivate( + new ActivateResultCallback() { + @Override + public void success(boolean success) { + call.resolve(); + } + + @Override + public void error(String message) { + call.reject(message); + } + } + ); + } catch (Exception ex) { + call.reject(ex.getLocalizedMessage()); + } + } + + @PluginMethod + public void fetchConfig(PluginCall call) { + try { + long minimumFetchIntervalInSeconds = call.getLong("minimumFetchIntervalInSeconds", 43200L); + implementation.fetchConfig( + minimumFetchIntervalInSeconds, + new FetchConfigResultCallback() { + @Override + public void success() { + call.resolve(); + } + + @Override + public void error(String message) { + call.reject(message); + } + } + ); + } catch (Exception ex) { + call.reject(ex.getLocalizedMessage()); + } + } + + @PluginMethod + public void getBoolean(PluginCall call) { + try { + String key = call.getString("key"); + if (key == null) { + call.reject(ERROR_KEY_MISSING); + return; + } + GetValueResult getValueResult = implementation.getBoolean(key); + JSObject result = new JSObject(); + result.put("value", getValueResult.value); + result.put("source", getValueResult.source); + call.resolve(result); + } catch (Exception ex) { + call.reject(ex.getLocalizedMessage()); + } + } + + @PluginMethod + public void getNumber(PluginCall call) { + try { + String key = call.getString("key"); + if (key == null) { + call.reject(ERROR_KEY_MISSING); + return; + } + GetValueResult getValueResult = implementation.getNumber(key); + JSObject result = new JSObject(); + result.put("value", getValueResult.value); + result.put("source", getValueResult.source); + call.resolve(result); + } catch (Exception ex) { + call.reject(ex.getLocalizedMessage()); + } + } + + @PluginMethod + public void getString(PluginCall call) { + try { + String key = call.getString("key"); + if (key == null) { + call.reject(ERROR_KEY_MISSING); + return; + } + GetValueResult getValueResult = implementation.getString(key); + JSObject result = new JSObject(); + result.put("value", getValueResult.value); + result.put("source", getValueResult.source); + call.resolve(result); + } catch (Exception ex) { + call.reject(ex.getLocalizedMessage()); + } + } + + @PluginMethod + public void setMinimumFetchInterval(PluginCall call) { + call.reject("Not available on Android."); + } +} diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/GetValueResult.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/GetValueResult.java new file mode 100644 index 00000000..8a58ea3e --- /dev/null +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/GetValueResult.java @@ -0,0 +1,12 @@ +package io.capawesome.capacitorjs.plugins.firebase.remoteconfig; + +public class GetValueResult { + + T value; + int source; + + public GetValueResult(T value, int source) { + this.value = value; + this.source = source; + } +} diff --git a/packages/remote-config/android/src/main/res/.gitkeep b/packages/remote-config/android/src/main/res/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/remote-config/android/src/test/java/com/getcapacitor/ExampleUnitTest.java b/packages/remote-config/android/src/test/java/com/getcapacitor/ExampleUnitTest.java new file mode 100644 index 00000000..a0fed0cf --- /dev/null +++ b/packages/remote-config/android/src/test/java/com/getcapacitor/ExampleUnitTest.java @@ -0,0 +1,18 @@ +package com.getcapacitor; + +import static org.junit.Assert.*; + +import org.junit.Test; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} diff --git a/packages/remote-config/ios/Plugin.xcodeproj/project.pbxproj b/packages/remote-config/ios/Plugin.xcodeproj/project.pbxproj new file mode 100644 index 00000000..ec323f2c --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcodeproj/project.pbxproj @@ -0,0 +1,595 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 48; + objects = { + +/* Begin PBXBuildFile section */ + 03FC29A292ACC40490383A1F /* Pods_Plugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B2A61DA5A1F2DD4F959604D /* Pods_Plugin.framework */; }; + 20C0B05DCFC8E3958A738AF2 /* Pods_PluginTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6753A823D3815DB436415E3 /* Pods_PluginTests.framework */; }; + 2F98D68224C9AAE500613A4C /* FirebaseRemoteConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F98D68124C9AAE400613A4C /* FirebaseRemoteConfig.swift */; }; + 50ADFF92201F53D600D50D53 /* Plugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50ADFF88201F53D600D50D53 /* Plugin.framework */; }; + 50ADFF97201F53D600D50D53 /* FirebaseRemoteConfigPluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50ADFF96201F53D600D50D53 /* FirebaseRemoteConfigPluginTests.swift */; }; + 50ADFF99201F53D600D50D53 /* FirebaseRemoteConfigPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 50ADFF8B201F53D600D50D53 /* FirebaseRemoteConfigPlugin.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 50ADFFA42020D75100D50D53 /* Capacitor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50ADFFA52020D75100D50D53 /* Capacitor.framework */; }; + 50ADFFA82020EE4F00D50D53 /* FirebaseRemoteConfigPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 50ADFFA72020EE4F00D50D53 /* FirebaseRemoteConfigPlugin.m */; }; + 50E1A94820377CB70090CE1A /* FirebaseRemoteConfigPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E1A94720377CB70090CE1A /* FirebaseRemoteConfigPlugin.swift */; }; + 7C2425692925898B003FE3BB /* FirebaseRemoteConfigHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C2425682925898B003FE3BB /* FirebaseRemoteConfigHelper.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 50ADFF93201F53D600D50D53 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 50ADFF7F201F53D600D50D53 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 50ADFF87201F53D600D50D53; + remoteInfo = Plugin; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 2F98D68124C9AAE400613A4C /* FirebaseRemoteConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteConfig.swift; sourceTree = ""; }; + 3B2A61DA5A1F2DD4F959604D /* Pods_Plugin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Plugin.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 50ADFF88201F53D600D50D53 /* Plugin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Plugin.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 50ADFF8B201F53D600D50D53 /* FirebaseRemoteConfigPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FirebaseRemoteConfigPlugin.h; sourceTree = ""; }; + 50ADFF8C201F53D600D50D53 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 50ADFF91201F53D600D50D53 /* PluginTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PluginTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 50ADFF96201F53D600D50D53 /* FirebaseRemoteConfigPluginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteConfigPluginTests.swift; sourceTree = ""; }; + 50ADFF98201F53D600D50D53 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 50ADFFA52020D75100D50D53 /* Capacitor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Capacitor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 50ADFFA72020EE4F00D50D53 /* FirebaseRemoteConfigPlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FirebaseRemoteConfigPlugin.m; sourceTree = ""; }; + 50E1A94720377CB70090CE1A /* FirebaseRemoteConfigPlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteConfigPlugin.swift; sourceTree = ""; }; + 5E23F77F099397094342571A /* Pods-Plugin.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Plugin.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig"; sourceTree = ""; }; + 7C2425682925898B003FE3BB /* FirebaseRemoteConfigHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseRemoteConfigHelper.swift; sourceTree = ""; }; + 91781294A431A2A7CC6EB714 /* Pods-Plugin.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Plugin.release.xcconfig"; path = "Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig"; sourceTree = ""; }; + 96ED1B6440D6672E406C8D19 /* Pods-PluginTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PluginTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig"; sourceTree = ""; }; + F65BB2953ECE002E1EF3E424 /* Pods-PluginTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PluginTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.release.xcconfig"; sourceTree = ""; }; + F6753A823D3815DB436415E3 /* Pods_PluginTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PluginTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 50ADFF84201F53D600D50D53 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 50ADFFA42020D75100D50D53 /* Capacitor.framework in Frameworks */, + 03FC29A292ACC40490383A1F /* Pods_Plugin.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 50ADFF8E201F53D600D50D53 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 50ADFF92201F53D600D50D53 /* Plugin.framework in Frameworks */, + 20C0B05DCFC8E3958A738AF2 /* Pods_PluginTests.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 50ADFF7E201F53D600D50D53 = { + isa = PBXGroup; + children = ( + 50ADFF8A201F53D600D50D53 /* Plugin */, + 50ADFF95201F53D600D50D53 /* PluginTests */, + 50ADFF89201F53D600D50D53 /* Products */, + 8C8E7744173064A9F6D438E3 /* Pods */, + A797B9EFA3DCEFEA1FBB66A9 /* Frameworks */, + ); + sourceTree = ""; + }; + 50ADFF89201F53D600D50D53 /* Products */ = { + isa = PBXGroup; + children = ( + 50ADFF88201F53D600D50D53 /* Plugin.framework */, + 50ADFF91201F53D600D50D53 /* PluginTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 50ADFF8A201F53D600D50D53 /* Plugin */ = { + isa = PBXGroup; + children = ( + 50E1A94720377CB70090CE1A /* FirebaseRemoteConfigPlugin.swift */, + 7C2425682925898B003FE3BB /* FirebaseRemoteConfigHelper.swift */, + 2F98D68124C9AAE400613A4C /* FirebaseRemoteConfig.swift */, + 50ADFF8B201F53D600D50D53 /* FirebaseRemoteConfigPlugin.h */, + 50ADFFA72020EE4F00D50D53 /* FirebaseRemoteConfigPlugin.m */, + 50ADFF8C201F53D600D50D53 /* Info.plist */, + ); + path = Plugin; + sourceTree = ""; + }; + 50ADFF95201F53D600D50D53 /* PluginTests */ = { + isa = PBXGroup; + children = ( + 50ADFF96201F53D600D50D53 /* FirebaseRemoteConfigPluginTests.swift */, + 50ADFF98201F53D600D50D53 /* Info.plist */, + ); + path = PluginTests; + sourceTree = ""; + }; + 8C8E7744173064A9F6D438E3 /* Pods */ = { + isa = PBXGroup; + children = ( + 5E23F77F099397094342571A /* Pods-Plugin.debug.xcconfig */, + 91781294A431A2A7CC6EB714 /* Pods-Plugin.release.xcconfig */, + 96ED1B6440D6672E406C8D19 /* Pods-PluginTests.debug.xcconfig */, + F65BB2953ECE002E1EF3E424 /* Pods-PluginTests.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; + A797B9EFA3DCEFEA1FBB66A9 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 50ADFFA52020D75100D50D53 /* Capacitor.framework */, + 3B2A61DA5A1F2DD4F959604D /* Pods_Plugin.framework */, + F6753A823D3815DB436415E3 /* Pods_PluginTests.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 50ADFF85201F53D600D50D53 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 50ADFF99201F53D600D50D53 /* FirebaseRemoteConfigPlugin.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 50ADFF87201F53D600D50D53 /* Plugin */ = { + isa = PBXNativeTarget; + buildConfigurationList = 50ADFF9C201F53D600D50D53 /* Build configuration list for PBXNativeTarget "Plugin" */; + buildPhases = ( + AB5B3E54B4E897F32C2279DA /* [CP] Check Pods Manifest.lock */, + 50ADFF83201F53D600D50D53 /* Sources */, + 50ADFF84201F53D600D50D53 /* Frameworks */, + 50ADFF85201F53D600D50D53 /* Headers */, + 50ADFF86201F53D600D50D53 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Plugin; + productName = Plugin; + productReference = 50ADFF88201F53D600D50D53 /* Plugin.framework */; + productType = "com.apple.product-type.framework"; + }; + 50ADFF90201F53D600D50D53 /* PluginTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 50ADFF9F201F53D600D50D53 /* Build configuration list for PBXNativeTarget "PluginTests" */; + buildPhases = ( + 0596884F929ED6F1DE134961 /* [CP] Check Pods Manifest.lock */, + 50ADFF8D201F53D600D50D53 /* Sources */, + 50ADFF8E201F53D600D50D53 /* Frameworks */, + 50ADFF8F201F53D600D50D53 /* Resources */, + 8E97F58B69A94C6503FC9C85 /* [CP] Embed Pods Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 50ADFF94201F53D600D50D53 /* PBXTargetDependency */, + ); + name = PluginTests; + productName = PluginTests; + productReference = 50ADFF91201F53D600D50D53 /* PluginTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 50ADFF7F201F53D600D50D53 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 1160; + ORGANIZATIONNAME = "Max Lynch"; + TargetAttributes = { + 50ADFF87201F53D600D50D53 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + }; + 50ADFF90201F53D600D50D53 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 50ADFF82201F53D600D50D53 /* Build configuration list for PBXProject "Plugin" */; + compatibilityVersion = "Xcode 8.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 50ADFF7E201F53D600D50D53; + productRefGroup = 50ADFF89201F53D600D50D53 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 50ADFF87201F53D600D50D53 /* Plugin */, + 50ADFF90201F53D600D50D53 /* PluginTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 50ADFF86201F53D600D50D53 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 50ADFF8F201F53D600D50D53 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 0596884F929ED6F1DE134961 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-PluginTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 8E97F58B69A94C6503FC9C85 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Capacitor/Capacitor.framework", + "${BUILT_PRODUCTS_DIR}/CapacitorCordova/Cordova.framework", + "${BUILT_PRODUCTS_DIR}/FirebaseABTesting/FirebaseABTesting.framework", + "${BUILT_PRODUCTS_DIR}/FirebaseCore/FirebaseCore.framework", + "${BUILT_PRODUCTS_DIR}/FirebaseCoreDiagnostics/FirebaseCoreDiagnostics.framework", + "${BUILT_PRODUCTS_DIR}/FirebaseCoreInternal/FirebaseCoreInternal.framework", + "${BUILT_PRODUCTS_DIR}/FirebaseInstallations/FirebaseInstallations.framework", + "${BUILT_PRODUCTS_DIR}/FirebaseRemoteConfig/FirebaseRemoteConfig.framework", + "${BUILT_PRODUCTS_DIR}/GoogleDataTransport/GoogleDataTransport.framework", + "${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework", + "${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework", + "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Capacitor.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cordova.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseABTesting.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCore.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreDiagnostics.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreInternal.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseInstallations.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseRemoteConfig.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleDataTransport.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + AB5B3E54B4E897F32C2279DA /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Plugin-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 50ADFF83201F53D600D50D53 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7C2425692925898B003FE3BB /* FirebaseRemoteConfigHelper.swift in Sources */, + 50E1A94820377CB70090CE1A /* FirebaseRemoteConfigPlugin.swift in Sources */, + 2F98D68224C9AAE500613A4C /* FirebaseRemoteConfig.swift in Sources */, + 50ADFFA82020EE4F00D50D53 /* FirebaseRemoteConfigPlugin.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 50ADFF8D201F53D600D50D53 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 50ADFF97201F53D600D50D53 /* FirebaseRemoteConfigPluginTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 50ADFF94201F53D600D50D53 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 50ADFF87201F53D600D50D53 /* Plugin */; + targetProxy = 50ADFF93201F53D600D50D53 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 50ADFF9A201F53D600D50D53 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + FRAMEWORK_SEARCH_PATHS = ( + "\"${BUILT_PRODUCTS_DIR}/Capacitor\"", + "\"${BUILT_PRODUCTS_DIR}/CapacitorCordova\"", + ); + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 50ADFF9B201F53D600D50D53 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + FRAMEWORK_SEARCH_PATHS = ( + "\"${BUILT_PRODUCTS_DIR}/Capacitor\"", + "\"${BUILT_PRODUCTS_DIR}/CapacitorCordova\"", + ); + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 50ADFF9D201F53D600D50D53 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5E23F77F099397094342571A /* Pods-Plugin.debug.xcconfig */; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; + CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = Plugin/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)"; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 50ADFF9E201F53D600D50D53 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 91781294A431A2A7CC6EB714 /* Pods-Plugin.release.xcconfig */; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; + CODE_SIGN_STYLE = Automatic; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = Plugin/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; + ONLY_ACTIVE_ARCH = NO; + PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 50ADFFA0201F53D600D50D53 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 96ED1B6440D6672E406C8D19 /* Pods-PluginTests.debug.xcconfig */; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = PluginTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.PluginTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 50ADFFA1201F53D600D50D53 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = F65BB2953ECE002E1EF3E424 /* Pods-PluginTests.release.xcconfig */; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = PluginTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.PluginTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 50ADFF82201F53D600D50D53 /* Build configuration list for PBXProject "Plugin" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 50ADFF9A201F53D600D50D53 /* Debug */, + 50ADFF9B201F53D600D50D53 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 50ADFF9C201F53D600D50D53 /* Build configuration list for PBXNativeTarget "Plugin" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 50ADFF9D201F53D600D50D53 /* Debug */, + 50ADFF9E201F53D600D50D53 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 50ADFF9F201F53D600D50D53 /* Build configuration list for PBXNativeTarget "PluginTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 50ADFFA0201F53D600D50D53 /* Debug */, + 50ADFFA1201F53D600D50D53 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 50ADFF7F201F53D600D50D53 /* Project object */; +} diff --git a/packages/remote-config/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/packages/remote-config/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/packages/remote-config/ios/Plugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/remote-config/ios/Plugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/remote-config/ios/Plugin.xcodeproj/xcshareddata/xcschemes/Plugin.xcscheme b/packages/remote-config/ios/Plugin.xcodeproj/xcshareddata/xcschemes/Plugin.xcscheme new file mode 100644 index 00000000..303f2621 --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcodeproj/xcshareddata/xcschemes/Plugin.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/remote-config/ios/Plugin.xcodeproj/xcshareddata/xcschemes/PluginTests.xcscheme b/packages/remote-config/ios/Plugin.xcodeproj/xcshareddata/xcschemes/PluginTests.xcscheme new file mode 100644 index 00000000..3d8c88d2 --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcodeproj/xcshareddata/xcschemes/PluginTests.xcscheme @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/remote-config/ios/Plugin.xcworkspace/contents.xcworkspacedata b/packages/remote-config/ios/Plugin.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..afad624e --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/packages/remote-config/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/packages/remote-config/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/packages/remote-config/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift b/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift new file mode 100644 index 00000000..8a1f586f --- /dev/null +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift @@ -0,0 +1,54 @@ +import Foundation + +import FirebaseCore +import FirebaseRemoteConfig + +@objc public class FirebaseRemoteConfig: NSObject { + private let plugin: FirebaseRemoteConfigPlugin + + init(plugin: FirebaseRemoteConfigPlugin) { + self.plugin = plugin + super.init() + if FirebaseApp.app() == nil { + FirebaseApp.configure() + } + } + + @objc public func activate(completion: @escaping (Bool, String?) -> Void) { + RemoteConfig.remoteConfig().activate(completion: { result, error in + if let error = error { + completion(false, error.localizedDescription) + return + } + completion(result, nil) + }) + } + + @objc public func fetchAndActivate(completion: @escaping (Bool, String?) -> Void) { + RemoteConfig.remoteConfig().fetchAndActivate(completionHandler: { result, error in + if let error = error { + completion(false, error.localizedDescription) + return + } + if result == .error { + completion(false, self.plugin.errorFetchAndActivatefailed) + } else { + completion(true, nil) + } + }) + } + + @objc public func fetchConfig(minimumFetchIntervalInSeconds: Double, completion: @escaping (String?) -> Void) { + RemoteConfig.remoteConfig().fetch(withExpirationDuration: minimumFetchIntervalInSeconds, completionHandler: { _, error in + if let error = error { + completion(error.localizedDescription) + return + } + completion(nil) + }) + } + + @objc public func getValue(_ key: String) -> RemoteConfigValue { + return RemoteConfig.remoteConfig().configValue(forKey: key) + } +} diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfigHelper.swift b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigHelper.swift new file mode 100644 index 00000000..3d5723de --- /dev/null +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigHelper.swift @@ -0,0 +1,14 @@ +import Foundation +import FirebaseRemoteConfig + +public class FirebaseRemoteConfigHelper { + public static func mapRemoteConfigSourceToInt(_ source: RemoteConfigSource) -> Int { + if source == .static { + return 0 + } else if source == .remote { + return 2 + } else { + return 1 + } + } +} diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.h b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.h new file mode 100644 index 00000000..f2bd9e0b --- /dev/null +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.h @@ -0,0 +1,10 @@ +#import + +//! Project version number for Plugin. +FOUNDATION_EXPORT double PluginVersionNumber; + +//! Project version string for Plugin. +FOUNDATION_EXPORT const unsigned char PluginVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.m b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.m new file mode 100644 index 00000000..543dbe9e --- /dev/null +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.m @@ -0,0 +1,14 @@ +#import +#import + +// Define the plugin using the CAP_PLUGIN Macro, and +// each method the plugin supports using the CAP_PLUGIN_METHOD macro. +CAP_PLUGIN(FirebaseRemoteConfigPlugin, "FirebaseRemoteConfig", + CAP_PLUGIN_METHOD(activate, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(fetchAndActivate, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(fetchConfig, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getBoolean, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getNumber, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getString, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(setMinimumFetchInterval, CAPPluginReturnPromise); +) diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift new file mode 100644 index 00000000..c36be5ad --- /dev/null +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift @@ -0,0 +1,91 @@ +import Foundation +import Capacitor + +/** + * Please read the Capacitor iOS Plugin Development Guide + * here: https://capacitorjs.com/docs/plugins/ios + */ +@objc(FirebaseRemoteConfigPlugin) +public class FirebaseRemoteConfigPlugin: CAPPlugin { + public let errorKeyMissing = "key must be provided." + public let errorFetchAndActivatefailed = "fetchAndActivate failed." + private var implementation: FirebaseRemoteConfig? + + override public func load() { + implementation = FirebaseRemoteConfig(plugin: self) + } + + @objc func activate(_ call: CAPPluginCall) { + implementation?.activate(completion: { _, errorMessage in + if let errorMessage = errorMessage { + call.reject(errorMessage) + return + } + call.resolve() + }) + call.resolve() + } + + @objc func fetchAndActivate(_ call: CAPPluginCall) { + implementation?.fetchAndActivate(completion: { _, errorMessage in + if let errorMessage = errorMessage { + call.reject(errorMessage) + return + } + call.resolve() + }) + call.resolve() + } + + @objc func fetchConfig(_ call: CAPPluginCall) { + let minimumFetchIntervalInSeconds = call.getDouble("minimumFetchIntervalInSeconds") ?? 43200 + implementation?.fetchConfig(minimumFetchIntervalInSeconds: minimumFetchIntervalInSeconds, completion: { errorMessage in + if let errorMessage = errorMessage { + call.reject(errorMessage) + return + } + call.resolve() + }) + call.resolve() + } + + @objc func getBoolean(_ call: CAPPluginCall) { + guard let key = call.getString("key") else { + call.reject(errorKeyMissing) + return + } + let value = implementation?.getValue(key) + call.resolve([ + "value": value!.boolValue, + "source": FirebaseRemoteConfigHelper.mapRemoteConfigSourceToInt(value!.source) + ]) + } + + @objc func getNumber(_ call: CAPPluginCall) { + guard let key = call.getString("key") else { + call.reject(errorKeyMissing) + return + } + let value = implementation?.getValue(key) + call.resolve([ + "value": value!.numberValue, + "source": FirebaseRemoteConfigHelper.mapRemoteConfigSourceToInt(value!.source) + ]) + } + + @objc func getString(_ call: CAPPluginCall) { + guard let key = call.getString("key") else { + call.reject(errorKeyMissing) + return + } + let value = implementation?.getValue(key) + call.resolve([ + "value": value!.stringValue ?? "", + "source": FirebaseRemoteConfigHelper.mapRemoteConfigSourceToInt(value!.source) + ]) + } + + @objc func setMinimumFetchInterval(_ call: CAPPluginCall) { + call.reject("Not available on iOS.") + } +} diff --git a/packages/remote-config/ios/Plugin/Info.plist b/packages/remote-config/ios/Plugin/Info.plist new file mode 100644 index 00000000..1007fd9d --- /dev/null +++ b/packages/remote-config/ios/Plugin/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/packages/remote-config/ios/PluginTests/FirebaseRemoteConfigPluginTests.swift b/packages/remote-config/ios/PluginTests/FirebaseRemoteConfigPluginTests.swift new file mode 100644 index 00000000..1957a337 --- /dev/null +++ b/packages/remote-config/ios/PluginTests/FirebaseRemoteConfigPluginTests.swift @@ -0,0 +1,25 @@ +import XCTest +@testable import Plugin + +class FirebaseRemoteConfigTests: XCTestCase { + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testEcho() { + // This is an example of a functional test case for a plugin. + // Use XCTAssert and related functions to verify your tests produce the correct results. + + let implementation = FirebaseRemoteConfig() + let value = "Hello, World!" + let result = implementation.echo(value) + + XCTAssertEqual(value, result) + } +} diff --git a/packages/remote-config/ios/PluginTests/Info.plist b/packages/remote-config/ios/PluginTests/Info.plist new file mode 100644 index 00000000..6c40a6cd --- /dev/null +++ b/packages/remote-config/ios/PluginTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/packages/remote-config/ios/Podfile b/packages/remote-config/ios/Podfile new file mode 100644 index 00000000..496ca76d --- /dev/null +++ b/packages/remote-config/ios/Podfile @@ -0,0 +1,17 @@ +platform :ios, '13.0' + +def capacitor_pods + # Comment the next line if you're not using Swift and don't want to use dynamic frameworks + use_frameworks! + pod 'Capacitor', :path => '../../../node_modules/@capacitor/ios' + pod 'CapacitorCordova', :path => '../../../node_modules/@capacitor/ios' +end + +target 'Plugin' do + capacitor_pods + pod 'Firebase/RemoteConfig', '9.1.0' +end + +target 'PluginTests' do + capacitor_pods +end diff --git a/packages/remote-config/package.json b/packages/remote-config/package.json new file mode 100644 index 00000000..626f24ba --- /dev/null +++ b/packages/remote-config/package.json @@ -0,0 +1,95 @@ +{ + "name": "@capacitor-firebase/remote-config", + "version": "1.2.0", + "description": "Capacitor plugin for Firebase Remote Config.", + "main": "dist/plugin.cjs.js", + "module": "dist/esm/index.js", + "types": "dist/esm/index.d.ts", + "unpkg": "dist/plugin.js", + "files": [ + "android/src/main/", + "android/build.gradle", + "dist/", + "ios/Plugin/", + "CapacitorFirebaseRemoteConfig.podspec" + ], + "author": "Robin Genz ", + "license": "Apache-2.0", + "homepage": "https://capawesome.io/", + "repository": { + "type": "git", + "url": "git+https://github.com/capawesome-team/capacitor-firebase.git" + }, + "bugs": { + "url": "https://github.com/capawesome-team/capacitor-firebase/issues" + }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/capawesome-team/" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/capawesome" + } + ], + "keywords": [ + "capacitor", + "plugin", + "native" + ], + "scripts": { + "verify": "npm run verify:ios && npm run verify:android && npm run verify:web", + "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..", + "verify:android": "cd android && ./gradlew clean build test && cd ..", + "verify:web": "npm run build", + "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint", + "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format", + "eslint": "eslint . --ext ts", + "prettier": "prettier \"**/*.{css,html,ts,js,java}\"", + "swiftlint": "node-swiftlint", + "docgen": "docgen --api FirebaseRemoteConfigPlugin --output-readme README.md --output-json dist/docs.json", + "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js", + "clean": "rimraf ./dist", + "watch": "tsc --watch", + "prepublishOnly": "npm run build" + }, + "devDependencies": { + "@capacitor/android": "4.0.1", + "@capacitor/cli": "4.0.1", + "@capacitor/core": "4.0.1", + "@capacitor/docgen": "0.2.0", + "@capacitor/ios": "4.0.1", + "@ionic/eslint-config": "0.3.0", + "@ionic/prettier-config": "1.0.1", + "@ionic/swiftlint-config": "1.1.2", + "eslint": "7.32.0", + "firebase": "9.6.4", + "prettier": "2.3.2", + "prettier-plugin-java": "1.0.2", + "rimraf": "3.0.2", + "rollup": "2.77.2", + "swiftlint": "1.0.1", + "typescript": "4.1.5" + }, + "peerDependencies": { + "@capacitor/core": "^4.0.0", + "firebase": "^9.0.0" + }, + "prettier": "@ionic/prettier-config", + "swiftlint": "@ionic/swiftlint-config", + "eslintConfig": { + "extends": "@ionic/eslint-config/recommended" + }, + "capacitor": { + "ios": { + "src": "ios" + }, + "android": { + "src": "android" + } + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/remote-config/rollup.config.js b/packages/remote-config/rollup.config.js new file mode 100644 index 00000000..e3296aef --- /dev/null +++ b/packages/remote-config/rollup.config.js @@ -0,0 +1,23 @@ +export default { + input: 'dist/esm/index.js', + output: [ + { + file: 'dist/plugin.js', + format: 'iife', + name: 'capacitorFirebaseRemoteConfig', + globals: { + '@capacitor/core': 'capacitorExports', + 'firebase/remote-config': 'firebaseRemoteConfigExports', + }, + sourcemap: true, + inlineDynamicImports: true, + }, + { + file: 'dist/plugin.cjs.js', + format: 'cjs', + sourcemap: true, + inlineDynamicImports: true, + }, + ], + external: ['@capacitor/core', 'firebase/remote-config'], +}; diff --git a/packages/remote-config/src/definitions.ts b/packages/remote-config/src/definitions.ts new file mode 100644 index 00000000..69dc6698 --- /dev/null +++ b/packages/remote-config/src/definitions.ts @@ -0,0 +1,191 @@ +export interface FirebaseRemoteConfigPlugin { + /** + * Make the last fetched configuration available to the getters. + * + * @since 1.3.0 + */ + activate(): Promise; + /** + * Perform fetch and activate operations. + * + * @since 1.3.0 + */ + fetchAndActivate(): Promise; + /** + * Fetch and cache configuration from the Remote Config service. + * + * @since 1.3.0 + */ + fetchConfig(options?: FetchConfigOptions): Promise; + /** + * Get the value for the given key as a boolean. + * + * @since 1.3.0 + */ + getBoolean(options: GetBooleanOptions): Promise; + /** + * Get the value for the given key as a number. + * + * @since 1.3.0 + */ + getNumber(options: GetNumberOptions): Promise; + /** + * Get the value for the given key as a string. + * + * @since 1.3.0 + */ + getString(options: GetStringOptions): Promise; + /** + * Set the minimum fetch interval. + * + * Only available on Web. + * + * @since 1.3.0 + */ + setMinimumFetchInterval( + options: SetMinimumFetchIntervalOptions, + ): Promise; +} + +/** + * @since 1.3.0 + */ +export interface GetOptions { + /** + * The key of the value to get. + * + * @since 1.3.0 + */ + key: string; +} + +/** + * @since 1.3.0 + */ +export interface FetchConfigOptions { + /** + * Define the maximum age in seconds of an entry in the config cache before it is considered stale. + * During development, it's recommended to set a relatively low minimum fetch interval. + * + * Only available on Android and iOS. + * + * @since 1.3.0 + * @default 43200 + * @see https://firebase.google.com/docs/reference/js/firebase.remoteconfig.RemoteConfigSettings#minimumfetchintervalmillis + */ + minimumFetchIntervalInSeconds?: number; +} + +/** + * @since 1.3.0 + */ +export type GetBooleanOptions = GetOptions; + +/** + * @since 1.3.0 + */ +export type GetNumberOptions = GetOptions; + +/** + * @since 1.3.0 + */ +export type GetStringOptions = GetOptions; + +/** + * @since 1.3.0 + */ +export interface GetBooleanResult { + /** + * The value for the given key as a boolean. + * + * @since 1.3.0 + */ + value: boolean; + /** + * Indicates at which source this value came from. + * + * Only available on Android and iOS. + * + * @since 1.3.0 + */ + source?: GetValueSource; +} + +/** + * @since 1.3.0 + */ +export interface GetNumberResult { + /** + * The value for the given key as a number. + * + * @since 1.3.0 + */ + value: number; + /** + * Indicates at which source this value came from. + * + * Only available on Android and iOS. + * + * @since 1.3.0 + */ + source?: GetValueSource; +} + +/** + * @since 1.3.0 + */ +export interface GetStringResult { + /** + * The value for the given key as a string. + * + * @since 1.3.0 + */ + value: string; + /** + * Indicates at which source this value came from. + * + * Only available on Android and iOS. + * + * @since 1.3.0 + */ + source?: GetValueSource; +} + +/** + * @since 1.3.0 + */ +export interface SetMinimumFetchIntervalOptions { + /** + * Define the maximum age in seconds of an entry in the config cache before it is considered stale. + * During development, it's recommended to set a relatively low minimum fetch interval. + * + * @since 1.3.0 + * @default 43200 + * @see https://firebase.google.com/docs/reference/js/firebase.remoteconfig.RemoteConfigSettings#minimumfetchintervalmillis + */ + minimumFetchIntervalInSeconds: number; +} + +/** + * @since 1.3.0 + */ +export enum GetValueSource { + /** + * Indicates that the value returned is the static default value. + * + * @since 1.3.0 + */ + Static = 0, + /** + * Indicates that the value returned was retrieved from the defaults set by the client. + * + * @since 1.3.0 + */ + Default = 1, + /** + * Indicates that the value returned was retrieved from the Firebase Remote Config Server. + * + * @since 1.3.0 + */ + Remote = 2, +} diff --git a/packages/remote-config/src/index.ts b/packages/remote-config/src/index.ts new file mode 100644 index 00000000..6959d8d0 --- /dev/null +++ b/packages/remote-config/src/index.ts @@ -0,0 +1,13 @@ +import { registerPlugin } from '@capacitor/core'; + +import type { FirebaseRemoteConfigPlugin } from './definitions'; + +const FirebaseRemoteConfig = registerPlugin( + 'FirebaseRemoteConfig', + { + web: () => import('./web').then(m => new m.FirebaseRemoteConfigWeb()), + }, +); + +export * from './definitions'; +export { FirebaseRemoteConfig }; diff --git a/packages/remote-config/src/web.ts b/packages/remote-config/src/web.ts new file mode 100644 index 00000000..9b5f4597 --- /dev/null +++ b/packages/remote-config/src/web.ts @@ -0,0 +1,65 @@ +import { WebPlugin } from '@capacitor/core'; +import { + activate, + fetchAndActivate, + fetchConfig, + getBoolean, + getNumber, + getRemoteConfig, + getString, +} from 'firebase/remote-config'; + +import type { + FirebaseRemoteConfigPlugin, + GetBooleanResult, + GetNumberResult, + GetOptions, + GetStringResult, + SetMinimumFetchIntervalOptions, +} from './definitions'; + +export class FirebaseRemoteConfigWeb + extends WebPlugin + implements FirebaseRemoteConfigPlugin +{ + public async activate(): Promise { + const remoteConfig = getRemoteConfig(); + await activate(remoteConfig); + } + + public async fetchAndActivate(): Promise { + const remoteConfig = getRemoteConfig(); + await fetchAndActivate(remoteConfig); + } + + public async fetchConfig(): Promise { + const remoteConfig = getRemoteConfig(); + await fetchConfig(remoteConfig); + } + + public async getBoolean(options: GetOptions): Promise { + const remoteConfig = getRemoteConfig(); + const value = getBoolean(remoteConfig, options.key); + return { value }; + } + + public async getNumber(options: GetOptions): Promise { + const remoteConfig = getRemoteConfig(); + const value = getNumber(remoteConfig, options.key); + return { value }; + } + + public async getString(options: GetOptions): Promise { + const remoteConfig = getRemoteConfig(); + const value = getString(remoteConfig, options.key); + return { value }; + } + + public async setMinimumFetchInterval( + options: SetMinimumFetchIntervalOptions, + ): Promise { + const remoteConfig = getRemoteConfig(); + remoteConfig.settings.minimumFetchIntervalMillis = + options.minimumFetchIntervalInSeconds * 1000; + } +} diff --git a/packages/remote-config/tsconfig.json b/packages/remote-config/tsconfig.json new file mode 100644 index 00000000..f2e88e6a --- /dev/null +++ b/packages/remote-config/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "allowUnreachableCode": false, + "declaration": true, + "esModuleInterop": true, + "inlineSources": true, + "lib": ["dom", "es2017"], + "module": "esnext", + "moduleResolution": "node", + "noFallthroughCasesInSwitch": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "outDir": "dist/esm", + "pretty": true, + "sourceMap": true, + "strict": true, + "target": "es2017" + }, + "files": ["src/index.ts"] +}