From a37fb517ca667cbb0bcf32a8080003fc980f3fdd Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 29 Oct 2021 11:40:07 +0200 Subject: [PATCH 1/6] feat(android): remove core requirement --- android/local.properties | 8 -------- android/manifest | 2 +- android/timodule.xml | 3 --- 3 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 android/local.properties diff --git a/android/local.properties b/android/local.properties deleted file mode 100644 index fca3c37..0000000 --- a/android/local.properties +++ /dev/null @@ -1,8 +0,0 @@ -## This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Tue Mar 31 20:21:59 CEST 2020 -sdk.dir=/home/miga/tools/Android/sdk diff --git a/android/manifest b/android/manifest index ced3a2b..dcfe7ee 100644 --- a/android/manifest +++ b/android/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 3.2.2 +version: 3.3.0 apiversion: 4 architectures: arm64-v8a armeabi-v7a x86 x86_64 description: titanium-firebase-cloud-messaging diff --git a/android/timodule.xml b/android/timodule.xml index c32346a..090a448 100644 --- a/android/timodule.xml +++ b/android/timodule.xml @@ -16,9 +16,6 @@ - - firebase.core - ti.playservices From c7724324279b9ced32307989353f209874fb88d6 Mon Sep 17 00:00:00 2001 From: m1ga Date: Fri, 29 Oct 2021 11:47:53 +0200 Subject: [PATCH 2/6] readme --- README.md | 50 +------------------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/README.md b/README.md index df1a324..6f93a27 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,9 @@ thank you! * [Build from source](#build) ## Requirements -- [x] The [Firebase Core](https://github.com/hansemannn/titanium-firebase-core) module. -The options `googleAppID` and `GCMSenderID` are required for Android, or `file` (e.g. `GoogleService-Info.plist`) for iOS. - [x] iOS: Titanium SDK 7.3.0+ (if you use SDK < 7.3.0, please use Ti.FirebaseCloudMessaging v1.1.0) - [x] Android: Titanium SDK 7.0.0+, [Ti.PlayServices](https://github.com/appcelerator-modules/ti.playservices) module -- [x] Read the [Firebase-Core](https://github.com/hansemannn/titanium-firebase#installation) install part if you set up a new project. +- [x] Read the [Titanium-Firebase](https://github.com/hansemannn/titanium-firebase#installation) install part if you set up a new project. ## Download @@ -92,42 +90,6 @@ Big text notification with colored icon/appname ### Updates to the Manifest -Merge the following keys to the `` section of the tiapp.xml in order to use GCM (not needed for FCM). - -```xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -``` - If you run into errors in combination with firebase.analytics e.g. `Error: Attempt to invoke virtual method 'getInstanceId()' on a null object reference` you can add: ```xml @@ -332,12 +294,6 @@ The propery `lastData` will contain the data part when you send a notification p Full example for Android/iOS: ```js -// Import core module -var core = require('firebase.core'); - -// Configure core module (required for all Firebase modules). -core.configure(); - // Important: The cloud messaging module has to imported after (!) the configure() // method of the core module is called var fcm = require('firebase.cloudmessaging'); @@ -566,10 +522,6 @@ ti build -p ios --build-only ### Android -> **Note**: When building for Android, make sure you have the [firebase.core](https://github.com/hansemannn/titanium-firebase-core) module installed globally (`~/Library/Application Support/Titanium/modules/android/firebase.core`). Otherwise, the firebase-iid library will not be referenced properly. - -Find the latest library version at https://firebase.google.com/docs/android/learn-more#compare-bom-versions - ```bash cd android ti build -p android --build-only From 9926744d12fa39f43807b68988b0a0dbaa939144 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sat, 30 Oct 2021 13:49:40 +0200 Subject: [PATCH 3/6] README --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6f93a27..54e9f34 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ thank you! * [Build from source](#build) ## Requirements -- [x] iOS: Titanium SDK 7.3.0+ (if you use SDK < 7.3.0, please use Ti.FirebaseCloudMessaging v1.1.0) +- [x] iOS: [Firebase-Core](https://github.com/hansemannn/titanium-firebase-core) +- [x] iOS: Titanium SDK 7.3.0+ - [x] Android: Titanium SDK 7.0.0+, [Ti.PlayServices](https://github.com/appcelerator-modules/ti.playservices) module - [x] Read the [Titanium-Firebase](https://github.com/hansemannn/titanium-firebase#installation) install part if you set up a new project. @@ -41,7 +42,7 @@ thank you! -To register for push notifications on iOS, startin in 2.0.0, you only need to call the Titanium related methods as the following: +To register for push notifications on iOS, you only need to call the Titanium related methods as the following: ```js // Listen to the notification settings event Ti.App.iOS.addEventListener('usernotificationsettings', function eventUserNotificationSettings() { @@ -294,6 +295,12 @@ The propery `lastData` will contain the data part when you send a notification p Full example for Android/iOS: ```js + +if (OS_IOS) { + var fc = require("firebase.core"); + fc.configure(); +} + // Important: The cloud messaging module has to imported after (!) the configure() // method of the core module is called var fcm = require('firebase.cloudmessaging'); From 1767527f5a189e80f1ebe993af652f420a614060 Mon Sep 17 00:00:00 2001 From: m1ga Date: Sat, 30 Oct 2021 13:57:01 +0200 Subject: [PATCH 4/6] update lib --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index afdd3e7..b04c699 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,5 +8,5 @@ dependencies { implementation "me.leolin:ShortcutBadger:1.1.22@aar" // get latest version from https://firebase.google.com/docs/android/learn-more#bom - implementation 'com.google.firebase:firebase-messaging:22.0.0' + implementation 'com.google.firebase:firebase-messaging:23.0.0' } From a0955732a0552d4dbf298c243398cb7007c3da4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kn=C3=B6chel?= Date: Sun, 31 Oct 2021 16:30:35 +0100 Subject: [PATCH 5/6] chore: update format --- README.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 54e9f34..7e2c33c 100644 --- a/README.md +++ b/README.md @@ -297,35 +297,35 @@ Full example for Android/iOS: ```js if (OS_IOS) { - var fc = require("firebase.core"); + const FirebaseCore = require('firebase.core'); fc.configure(); } // Important: The cloud messaging module has to imported after (!) the configure() // method of the core module is called -var fcm = require('firebase.cloudmessaging'); +const FirebaseCloudMessaging = require('firebase.cloudmessaging'); // Called when the Firebase token is registered or refreshed. -fcm.addEventListener('didRefreshRegistrationToken', function(e) { +FirebaseCloudMessaging.addEventListener('didRefreshRegistrationToken', function(e) { Ti.API.info('Token', e.fcmToken); }); // Called when direct messages arrive. Note that these are different from push notifications. -fcm.addEventListener('didReceiveMessage', function(e) { +FirebaseCloudMessaging.addEventListener('didReceiveMessage', function(e) { Ti.API.info('Message', e.message); }); // Android-only: For configuring custom sounds and importance for the generated system // notifications when app is in the background if (OS_ANDROID) { - // fcm.createNotificationChannel({ + // FirebaseCloudMessaging.createNotificationChannel({ // sound: 'warn_sound', // channelId: 'default', // channelName: 'General Notifications', // importance: 'high' - // }) + // }); - var channel = Ti.Android.NotificationManager.createNotificationChannel({ + const channel = Ti.Android.NotificationManager.createNotificationChannel({ id: 'default', name: 'Default channel', importance: Ti.Android.IMPORTANCE_DEFAULT, @@ -335,10 +335,10 @@ if (OS_ANDROID) { }); // if you use a custom id you have to set the same to the `channelId` in you php send script! - fcm.notificationChannel = channel; + FirebaseCloudMessaging.notificationChannel = channel; // display last data: - Ti.API.info("Last data: " + fcm.lastData); + Ti.API.info(`Last data: ${FirebaseCloudMessaging.lastData}`); } else { // iOS // Listen to the notification settings event @@ -349,8 +349,8 @@ if (OS_ANDROID) { // Register for push notifications Ti.Network.registerForPushNotifications({ success: function () { - if (fcm != null) { - console.log("New token", fcm.fcmToken); + if (!!fcm) { + console.log('New token', fcm.fcmToken); } }, error: function (e) { @@ -374,17 +374,19 @@ if (OS_ANDROID) { } // Register the device with the FCM service. -if (OS_ANDROID) fcm.registerForPushNotifications(); +if (OS_ANDROID) { + FirebaseCloudMessaging.registerForPushNotifications(); +} // Check if token is already available. -if (fcm.fcmToken) { - Ti.API.info('FCM-Token', fcm.fcmToken); +if (FirebaseCloudMessaging.fcmToken) { + Ti.API.info('FCM-Token', FirebaseCloudMessaging.fcmToken); } else { Ti.API.info('Token is empty. Waiting for the token callback ...'); } // Subscribe to a topic. -fcm.subscribeToTopic('testTopic'); +FirebaseCloudMessaging.subscribeToTopic('testTopic'); ``` Example to get the the resume data/notification click data on Android: @@ -394,7 +396,7 @@ const handleNotificationData = (notifObj) => { if (notifObj) { notifData = JSON.parse(notifObj); // ...process notification data... - fcm.clearLastData(); + FirebaseCloudMessaging.clearLastData(); } } @@ -405,7 +407,7 @@ handleNotificationData(launchIntent.getStringExtra("fcm_data")); Ti.App.addEventListener('resumed', function() { // App was resumed from background on notification click const currIntent = Titanium.Android.currentActivity.intent; - var notifData = currIntent.getStringExtra("fcm_data"); + const notifData = currIntent.getStringExtra("fcm_data"); handleNotificationData(notifData); }); ``` From c3929d92b40ea8d1cebcd706d40eaa931ac49ba9 Mon Sep 17 00:00:00 2001 From: m1ga Date: Mon, 22 Nov 2021 10:50:05 +0100 Subject: [PATCH 6/6] fix android 12+ target warning --- .../src/firebase/cloudmessaging/TiFirebaseMessagingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java b/android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java index e38e9ca..5ab303b 100644 --- a/android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java +++ b/android/src/firebase/cloudmessaging/TiFirebaseMessagingService.java @@ -177,7 +177,7 @@ private Boolean showNotification(RemoteMessage remoteMessage) int requestCode = (int)(System.currentTimeMillis() / 1000); PendingIntent contentIntent = - PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_ONE_SHOT); + PendingIntent.getActivity(this, requestCode, notificationIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT); // Start building notification