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

onTokenRefresh in FirebaseInstanceIDService has been deprecated #583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,18 @@ Send a push notification to a single device or topic.
- If the user taps the notification, the application comes to foreground and the notification data is received in the JavaScript callback.
- If the user does not tap the notification but opens the applicacion, nothing happens until the notification is tapped.

## Delete InstanceId

```javascript
// Stops device from receiving Firebase notifications, returns a promise
// Note: Deleting the Firebase instance triggers a token refresh,
// have to prevent the refreshed token from being sent to the server to stop notifications
FCMPlugin.deleteInstanceId().then(()=>{
// success
}, err => {
//error
})
```
## License
```
The MIT License
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 19 additions & 25 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,79 @@
<description>Cordova FCM Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova, fcm, push, plugin</keywords>

<info>
Cordova FCM plugin v2.1.2 installed
For more details visit https://github.com/fechanique/cordova-plugin-fcm
</info>

<js-module src="www/FCMPlugin.js" name="FCMPlugin">
<clobbers target="FCMPlugin" />
</js-module>

<engines>
<engine name="cordova-android" version=">=4.0.0" />
</engines>

<!-- ANDROID CONFIGURATION -->
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:exported="true" android:name="com.gae.scaffolder.plugin.FCMPluginActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="FCM_PLUGIN_ACTIVITY" />
<intent-filter>
<action android:name="FCM_PLUGIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</intent-filter>
</activity>
<service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.gae.scaffolder.plugin.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</config-file>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="FCMPlugin" >
<param name="android-package" value="com.gae.scaffolder.plugin.FCMPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>

<framework src="com.google.firebase:firebase-core:+" />
<framework src="com.google.firebase:firebase-messaging:+" />

<framework src="src/android/FCMPlugin.gradle" custom="true" type="gradleReference"/>

<source-file src="src/android/FCMPlugin.java" target-dir="src/com/gae/scaffolder/plugin" />
<source-file src="src/android/MyFirebaseMessagingService.java" target-dir="src/com/gae/scaffolder/plugin" />
<source-file src="src/android/MyFirebaseInstanceIDService.java" target-dir="src/com/gae/scaffolder/plugin" />
<source-file src="src/android/FCMPluginActivity.java" target-dir="src/com/gae/scaffolder/plugin" />
</platform>

<!-- IOS CONFIGURATION -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="FCMPlugin">
<param name="ios-package" value="FCMPlugin"/>
</feature>
</config-file>

<!-- ENABLE PUSH CAPABILITY -->
<config-file parent="aps-environment" target="*/Entitlements-Debug.plist">
<string>development</string>
</config-file>
<config-file parent="aps-environment" target="*/Entitlements-Release.plist">
<string>production</string>
</config-file>

<resource-file src="src/ios/GoogleService-Info.plist" target="Resources/GoogleService-Info.plist" />

<header-file src="src/ios/FCMPlugin.h" />
<source-file src="src/ios/FCMPlugin.m" />

<header-file src="src/ios/AppDelegate+FCMPlugin.h" />
<source-file src="src/ios/AppDelegate+FCMPlugin.m" />

<!-- FIREBASE COCOA PODS (not for the moment)-->
<!-- <framework src="Firebase/Messaging" type="podspec" spec="~> 0"/> -->

<!-- FIREBASE LIBS -->
<header-file src="src/ios/firebase/Firebase.h" />
<framework src="src/ios/firebase/FirebaseAnalytics.framework" custom="true" />
Expand All @@ -113,7 +107,7 @@
<framework src="src/ios/firebase/GoogleIPhoneUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleSymbolUtilities.framework" custom="true" />
<framework src="src/ios/firebase/GoogleUtilities.framework" custom="true" />

<!-- OTHER NEEDED LIBS -->
<framework src="libc++.tbd" />
<framework src="libz.tbd" />
Expand All @@ -122,9 +116,9 @@
<framework src="libz.tbd" />
<framework src="Security.framework" />
</platform>

<!-- COPY FCM CONFIG FILES TO PLATFORM AFTER PLUGIN INSTALL OR PLATFORM PREPARE -->
<hook src="scripts/fcm_config_files_process.js" type="after_plugin_add" />
<hook src="scripts/fcm_config_files_process.js" type="after_prepare" />

</plugin>
42 changes: 28 additions & 14 deletions src/android/FCMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,55 @@
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.iid.FirebaseInstanceId;


import java.util.Map;

public class FCMPlugin extends CordovaPlugin {

private static final String TAG = "FCMPlugin";

public static CordovaWebView gWebView;
public static String notificationCallBack = "FCMPlugin.onNotificationReceived";
public static String tokenRefreshCallBack = "FCMPlugin.onTokenRefreshReceived";
public static Boolean notificationCallBackReady = false;
public static Map<String, Object> lastPush = null;

public FCMPlugin() {}

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
gWebView = webView;
Log.d(TAG, "==> FCMPlugin initialize");
FirebaseMessaging.getInstance().subscribeToTopic("android");
FirebaseMessaging.getInstance().subscribeToTopic("all");
}

public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {

Log.d(TAG,"==> FCMPlugin execute: "+ action);

try{
// READY //
if (action.equals("ready")) {
//
callbackContext.success();
}
else if (action.equals("deleteInstanceId")) {
cordova.getThreadPool().execute(new Runnable() {

public void run() {
try {
FirebaseInstanceId.getInstance().deleteInstanceId();
callbackContext.success();
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
}
// GET TOKEN //
else if (action.equals("getToken")) {
cordova.getActivity().runOnUiThread(new Runnable() {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try{
String token = FirebaseInstanceId.getInstance().getToken();
Expand All @@ -64,7 +78,7 @@ public void run() {
// NOTIFICATION CALLBACK REGISTER //
else if (action.equals("registerNotification")) {
notificationCallBackReady = true;
cordova.getActivity().runOnUiThread(new Runnable() {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
if(lastPush != null) FCMPlugin.sendPushPayload( lastPush );
lastPush = null;
Expand Down Expand Up @@ -106,21 +120,21 @@ public void run() {
callbackContext.error(e.getMessage());
return false;
}

//cordova.getThreadPool().execute(new Runnable() {
// public void run() {
// //
// }
//});
//cordova.getActivity().runOnUiThread(new Runnable() {

//cordova.getThreadPool().execute(new Runnable() {
// public void run() {
// //
// }
//});
return true;
}

public static void sendPushPayload(Map<String, Object> payload) {
Log.d(TAG, "==> FCMPlugin sendPushPayload");
Log.d(TAG, "\tnotificationCallBackReady: " + notificationCallBackReady);
Expand Down Expand Up @@ -154,10 +168,10 @@ public static void sendTokenRefresh(String token) {
Log.d(TAG, "\tERROR sendRefreshToken: " + e.getMessage());
}
}

@Override
public void onDestroy() {
gWebView = null;
notificationCallBackReady = false;
}
}
}
25 changes: 0 additions & 25 deletions src/android/MyFirebaseInstanceIDService.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/android/MyFirebaseMessagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = "FCMPlugin";

@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.d("NEW_TOKEN",s);
}

/**
* Called when message is received.
*
Expand Down
1 change: 1 addition & 0 deletions src/ios/FCMPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- (void)registerNotification:(CDVInvokedUrlCommand*)command;
- (void)notifyOfMessage:(NSData*) payload;
- (void)notifyOfTokenRefresh:(NSString*) token;
- (void)unregister:(CDVInvokedUrlCommand*)command;
- (void)appEnterBackground;
- (void)appEnterForeground;

Expand Down
Loading