Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Firebase SDK #22

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a146969
fixed compilation error TS2794: Expected 1 arguments, but got 0
mic345 Dec 6, 2020
ca569f6
fixed #13
Dec 7, 2020
f5a7864
fixed Firebase script is loaded several times
Dec 7, 2020
8c817ea
fixed bug configure() warns Firebase App has not yet initialized.
Dec 7, 2020
ec44bc3
[refactor] simplify isFirebaseInitialized
Dec 7, 2020
d97cf04
[refactor] gather plugins' common code together
Dec 7, 2020
abc2712
[refactor] remove debug info
Dec 7, 2020
a26e23f
[refactor] simplify code
Dec 7, 2020
49298e5
[refactor] clarify method purpose
Dec 7, 2020
1efb9fd
Update to work with Firebase 7.x
Dec 7, 2020
677a800
fixed firebase may not be ready on firebaseObjectReadyPromise
Dec 8, 2020
2f6d99d
fixed [bug] getter functions return wrong types
Dec 8, 2020
9ee3bb4
[refactor] reuse existing code (not fixing the bug on the return type)
Dec 8, 2020
e47f417
fixed error TS6133: 'RCReturnDataArray' is declared but its value is…
Dec 8, 2020
2c829e8
fixed [bug] generic getValue is not available on native plugin interf…
Dec 10, 2020
43d1ae9
fixed [bug] Error: x.activate is not a function on iOS
Dec 10, 2020
fd7a3e2
[privacy] remnove redundent firebase podfile
Dec 14, 2020
d2b7b42
Rename CapacitorCommunity to JoinFlux
gugahoi Mar 15, 2021
64d0299
Bump version 0.3.1-alpha.5
gugahoi Mar 15, 2021
52a8369
Bump firebase version
gugahoi Mar 16, 2021
3d65857
Convert from promises to async/await
gugahoi Mar 16, 2021
746806f
Add noop ios functions
gugahoi Mar 16, 2021
feac800
Convert call.error to call.reject
gugahoi Mar 16, 2021
02d38bc
Change setDefaultWebConfig to setDefaultConfig
gugahoi Mar 16, 2021
e7aa6fd
Add noop android methods
gugahoi Mar 16, 2021
3ecf6f8
Remove web only information in README
gugahoi Mar 16, 2021
1434c6f
Replace call.error with call.reject in Android
gugahoi Mar 16, 2021
a70f831
Bump to version 0.3.1
gugahoi Mar 16, 2021
cebdaba
Migrate to using the Firebase SDK from npm
gugahoi Apr 27, 2021
86c68ca
Bump v0.4.0
gugahoi Apr 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions CapacitorCommunityFirebaseRemoteConfig.podspec

This file was deleted.

18 changes: 18 additions & 0 deletions JoinfluxFirebaseRemoteConfig.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'json'

package = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'package.json')))

Pod::Spec.new do |s|
s.name = 'JoinfluxFirebaseRemoteConfig'
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 = '11.0'
s.dependency 'Capacitor'
s.static_framework = true
s.dependency 'Firebase/RemoteConfig'
end
77 changes: 34 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
# Capacitor Firebase Remote Config Plugin

Capacitory community plugin for firebase remote config.

## Maintainers

| Maintainer | GitHub | Social | Sponsoring Company |
| ------------- | ------------------------------------------- | ------------------------------------------------ | ------------------ |
| Priyank Patel | [priyankpat](https://github.com/priyankpat) | [@priyankpat\_](https://twitter.com/priyankpat_) | Ionic |

Mainteinance Status: Actively Maintained
Capacitor community plugin for firebase remote config.

## Installation

To use npm

```bash
npm install @capacitor-community/firebase-remote-config
npm install @joinflux/firebase-remote-config
```

To use yarn

```bash
yarn add @capacitor-community/firebase-remote-config
yarn add @joinflux/firebase-remote-config
```

Sync native files
Expand Down Expand Up @@ -61,51 +53,43 @@ public class MainActivity extends BridgeActivity {

## Configuration

Download appropriate google-services.json or GoogleService-Info.plist and place it in the correct platform app directory.
Download appropriate google-services.json or GoogleService-Info.plist and place
it in the correct platform app directory.

**For Android**: /android/app

**For iOS**: /ios/App/App

## Examples

[Click here](https://github.com/priyankpat/capacitor-plugins-example/tree/firebase-remote-config) for example on how to implement this plugin

You can also clone the repository

```bash
git clone https://github.com/priyankpat/capacitor-plugins-example
git checkout -b firebase-remote-config
```

## Supported methods

| Name | Android | iOS | Web |
| :------------------ | :------ | :-- | :-- |
| initializeFirebase | ❌ | | ✅ |
| setDefaultWebConfig | ❌ | | ✅ |
| initialize | ✅ | ✅ | ✅ |
| fetch | ✅ | ✅ | ✅ |
| activate | ✅ | ✅ | ✅ |
| fetchAndActivate | ✅ | ✅ | ✅ |
| getBoolean | ✅ | ✅ | ✅ |
| getByteArray | ✅ | ✅ | ✅ |
| getNumber | ✅ | ✅ | ✅ |
| getString | ✅ | ✅ | ✅ |
| Name | Android | iOS | Web |
| :----------------- | :------ | :-- | :-- |
| initializeFirebase | ✅ | | ✅ |
| setDefaultConfig | ✅ | | ✅ |
| initialize | ✅ | ✅ | ✅ |
| fetch | ✅ | ✅ | ✅ |
| activate | ✅ | ✅ | ✅ |
| fetchAndActivate | ✅ | ✅ | ✅ |
| getBoolean | ✅ | ✅ | ✅ |
| getByteArray | ✅ | ✅ | ✅ |
| getNumber | ✅ | ✅ | ✅ |
| getString | ✅ | ✅ | ✅ |

## Usage

```typescript
// Must import the package once to make sure the web support initializes
import "@capacitor-community/firebase-remote-config";
import "@joinflux/firebase-remote-config";

import { Plugins } from "@capacitor/core";

const { FirebaseRemoteConfig } = Plugins;

/**
* NOTE: Web Platform only!
* This method will initialize firebase app if not yet initialized.
* This method will initialize firebase app if not yet initialized. Note that it
* is safe to call but does nothing in iOS or Android as initialization is
* automatic on load.
*
* @param firebase configs - from google-service.json or GoogleService-Info.plist
* @returns void
*/
Expand All @@ -121,18 +105,22 @@ FirebaseRemoteConfig.initializeFirebase({
});

/**
* NOTE: Web Platform only!
* This method will set default remote config values.
* This method will set default remote config values. On Web, it will read from
* the parameters give. On Android and iOS it will use the build in mechanisms
* and ignore any parameters supplied.
*
* @param options - key/value params with default values
* @returns void
*/
FirebaseRemoteConfig.setDefaultWebConfig({
FirebaseRemoteConfig.setDefaultConfig({
has_sale: false,
event_name: "clearance_event",
});

/**
* This method will configure remote config object instance and set the minimum fetch interval to allow for frequest refreshes.
* This method will configure remote config object instance and set the minimum
* fetch interval to allow for frequest refreshes.
*
* @param minimumFetchIntervalInSeconds - interval in seconds (default: 3600)
* @returns void
*/
Expand All @@ -149,13 +137,16 @@ FirebaseRemoteConfig.fetch();

/**
* This method will activate the fetched values making it available for your app
*
* @param none
* @returns void
*/
FirebaseRemoteConfig.activate();

/**
* This method will fetch and activate the values making it available for your app
* This method will fetch and activate the values making it available for your
* app
*
* @param none
* @returns void
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ public void load() {

this.mFirebaseRemoteConfig =
com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance();

String fileName = bridge
.getActivity()
.getPreferences(Context.MODE_PRIVATE)
.getString("FirebaseRemoteConfigDefaults", "");
if (fileName.isEmpty()) {
this.mFirebaseRemoteConfig.setDefaultsAsync(
Collections.<String, Object>emptyMap()
);
} else {
Context context = bridge.getActivity().getApplicationContext();
int resourceId = context
.getResources()
.getIdentifier(fileName, "xml", context.getPackageName());
this.mFirebaseRemoteConfig.setDefaultsAsync(resourceId);
}
}

@PluginMethod
Expand All @@ -72,9 +56,9 @@ public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
call.success();
} else if (task.isCanceled()) {
call.error(task.getException().getMessage());
call.reject(task.getException().getMessage());
} else {
call.error(task.getException().getMessage());
call.reject(task.getException().getMessage());
}
}
}
Expand All @@ -93,9 +77,9 @@ public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
call.success();
} else if (task.isCanceled()) {
call.error(task.getException().getMessage());
call.reject(task.getException().getMessage());
} else {
call.error(task.getException().getMessage());
call.reject(task.getException().getMessage());
}
}
}
Expand All @@ -114,9 +98,9 @@ public void onComplete(@NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
call.success();
} else if (task.isCanceled()) {
call.error(task.getException().getMessage());
call.reject(task.getException().getMessage());
} else {
call.error(task.getException().getMessage());
call.reject(task.getException().getMessage());
}
}
}
Expand All @@ -126,7 +110,7 @@ public void onComplete(@NonNull Task<Boolean> task) {

@Override
public void onFailure(@NonNull Exception e) {
call.error(e.getLocalizedMessage());
call.reject(e.getLocalizedMessage());
}
}
);
Expand All @@ -142,7 +126,7 @@ public void getBoolean(PluginCall call) {
result.put("source", getFirebaseRCValue(key).getSource());
call.success(result);
} else {
call.error(ERROR_MISSING_KEY);
call.reject(ERROR_MISSING_KEY);
}
}

Expand All @@ -156,7 +140,7 @@ public void getByteArray(PluginCall call) {
result.put("source", getFirebaseRCValue(key).getSource());
call.success(result);
} else {
call.error(ERROR_MISSING_KEY);
call.reject(ERROR_MISSING_KEY);
}
}

Expand All @@ -170,7 +154,7 @@ public void getNumber(PluginCall call) {
result.put("source", getFirebaseRCValue(key).getSource());
call.success(result);
} else {
call.error(ERROR_MISSING_KEY);
call.reject(ERROR_MISSING_KEY);
}
}

Expand All @@ -184,10 +168,37 @@ public void getString(PluginCall call) {
result.put("source", getFirebaseRCValue(key).getSource());
call.success(result);
} else {
call.error(ERROR_MISSING_KEY);
call.reject(ERROR_MISSING_KEY);
}
}

@PluginMethod
public void initializeFirebase(PluginCall call) {
call.success();
}

@PluginMethod
public void setDefaultConfig(PluginCall call) {
String fileName = bridge
.getActivity()
.getPreferences(Context.MODE_PRIVATE)
.getString("FirebaseRemoteConfigDefaults", "");

if (fileName.isEmpty()) {
this.mFirebaseRemoteConfig.setDefaultsAsync(
Collections.<String, Object>emptyMap()
);
} else {
Context context = bridge.getActivity().getApplicationContext();
int resourceId = context
.getResources()
.getIdentifier(fileName, "xml", context.getPackageName());
this.mFirebaseRemoteConfig.setDefaultsAsync(resourceId);
}

call.success();
}

private FirebaseRemoteConfigValue getFirebaseRCValue(String key) {
return this.mFirebaseRemoteConfig.getValue(key);
}
Expand Down
4 changes: 3 additions & 1 deletion ios/Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
CAP_PLUGIN(FirebaseRemoteConfig, "FirebaseRemoteConfig",
CAP_PLUGIN_METHOD(initialize, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(fetch, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(active, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(activate, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(fetchAndActivate, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getBoolean, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getString, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getNumber, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getByteArray, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(setDefaultConfig, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(initializeFirebase, CAPPluginReturnPromise);
)
Loading