diff --git a/.gitignore b/.gitignore index 562f376ce..ee70e679f 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ Temporary Items npm-debug.log node_modules + +.idea/ \ No newline at end of file diff --git a/ionic/FCM.d.ts b/ionic/FCM.d.ts deleted file mode 100644 index e37567904..000000000 --- a/ionic/FCM.d.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { Observable } from 'rxjs'; -import { INotificationPayload } from '../typings/INotificationPayload'; -import { IRequestPushPermissionOptions } from '../typings/IRequestPushPermissionOptions'; -import { IChannelConfiguration } from '../typings/IChannelConfiguration'; -/** - * @name FCM - * @description - * Easy plug&play push notification for Google Firebase FCM. - * - * @interfaces - * INotificationPayload - * IChannelConfiguration - * IRequestPushPermissionOptions - */ -export declare class FCMPluginOnIonic { - /** - * Removes existing push notifications from the notifications center - * - * @returns {Promise} Async call to native implementation - */ - clearAllNotifications(): Promise; - /** - * For Android, some notification properties are only defined programmatically. - * Channel can define the default behavior for notifications on Android 8.0+. - * Once a channel is created, it stays unchangeable until the user uninstalls the app. - * - * @param {IChannelConfiguration} channelConfig The parmeters of the new channel - * - * @returns {Promise} Async call to native implementation - */ - createNotificationChannel(channelConfig: IChannelConfiguration): Promise; - /** - * This method deletes the InstanceId, revoking all tokens. - * - * @returns {Promise} Async call to native implementation - */ - deleteInstanceId(): Promise; - /** - * Gets ios device's current APNS token - * - * @returns {Promise} Returns a Promise that resolves with the APNS token - */ - getAPNSToken(): Promise; - /** - * Retrieves the message that, on tap, opened the app - * - * @private - * - * @returns {Promise} Async call to native implementation - */ - getInitialPushPayload(): Promise; - /** - * Gets device's current registration id - * - * @returns {Promise} Returns a Promise that resolves with the registration id token - */ - getToken(): Promise; - /** - * Checking for permissions. - * - * @returns {Promise} Returns a Promise of: - * - true: push was allowed (or platform is android) - * - false: push will not be available - * - null: still not answered, recommended checking again later. - */ - hasPermission(): Promise; - /** - * Event firing when receiving new notifications - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for notification data - */ - onNotification(options?: { - once?: boolean; - }): Observable; - /** - * Event firing when receiving a new Firebase token - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for the token - */ - onTokenRefresh(options?: { - once?: boolean; - }): Observable; - /** - * Request push notification permission, alerting the user if it not have yet decided - * - * @param {IRequestPushPermissionOptions} options Options for push request - * @returns {Promise} Returns a Promise that resolves with the permission status - */ - requestPushPermission(options?: IRequestPushPermissionOptions): Promise; - /** - * Subscribes you to a [topic](https://firebase.google.com/docs/notifications/android/console-topics) - * - * @param {string} topic Topic to be subscribed to - * - * @returns {Promise} Async call to native implementation - */ - subscribeToTopic(topic: string): Promise; - /** - * Unsubscribes you from a [topic](https://firebase.google.com/docs/notifications/android/console-topics) - * - * @param {string} topic Topic to be unsubscribed from - * - * @returns {Promise} Async call to native implementation - */ - unsubscribeFromTopic(topic: string): Promise; -} -export declare const FCM: FCMPluginOnIonic; diff --git a/ionic/FCM.js b/ionic/FCM.js deleted file mode 100644 index 820fe3b8e..000000000 --- a/ionic/FCM.js +++ /dev/null @@ -1,51 +0,0 @@ -import { Subject } from 'rxjs' - -function FCMPluginOnIonic() {} -FCMPluginOnIonic.prototype.clearAllNotifications = function () { - return window.FCM.clearAllNotifications() -} -FCMPluginOnIonic.prototype.createNotificationChannel = function (channelConfig) { - return window.FCM.createNotificationChannel(channelConfig) -} -FCMPluginOnIonic.prototype.deleteInstanceId = function () { - return window.FCM.deleteInstanceId() -} -FCMPluginOnIonic.prototype.getAPNSToken = function () { - return window.FCM.getAPNSToken() -} -FCMPluginOnIonic.prototype.getInitialPushPayload = function () { - return window.FCM.getInitialPushPayload() -} -FCMPluginOnIonic.prototype.getToken = function () { - return window.FCM.getToken() -} -FCMPluginOnIonic.prototype.hasPermission = function () { - return window.FCM.hasPermission() -} -FCMPluginOnIonic.prototype.onNotification = function (options) { - var observable = new Subject() - var handler = function (payload) { - return observable.next(payload) - } - window.FCM.onNotification(handler, options) - return observable -} -FCMPluginOnIonic.prototype.onTokenRefresh = function (options) { - var observable = new Subject() - window.FCM.onTokenRefresh(function (token) { - return observable.next(token) - }, options) - return observable -} -FCMPluginOnIonic.prototype.requestPushPermission = function (options) { - return window.FCM.requestPushPermission(options) -} -FCMPluginOnIonic.prototype.subscribeToTopic = function (topic) { - return window.FCM.subscribeToTopic(topic) -} -FCMPluginOnIonic.prototype.unsubscribeFromTopic = function (topic) { - return window.FCM.unsubscribeFromTopic(topic) -} - -export { FCMPluginOnIonic } -export var FCM = new FCMPluginOnIonic() diff --git a/ionic/ngx/FCM.d.ts b/ionic/ngx/FCM.d.ts deleted file mode 100644 index b48dd761d..000000000 --- a/ionic/ngx/FCM.d.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { Observable } from 'rxjs'; -import { IChannelConfiguration } from '../../typings/IChannelConfiguration'; -import { INotificationPayload } from '../../typings/INotificationPayload'; -import { IRequestPushPermissionOptions } from '../../typings/IRequestPushPermissionOptions'; -/** - * @name FCM - * @description - * Easy plug&play push notification for Google Firebase FCM. - * - * @interfaces - * INotificationPayload - * IChannelConfiguration - * IRequestPushPermissionOptions - */ -export declare class FCM { - static pluginName: string; - static plugin: string; - static pluginRef: string; - static repo: string; - static platforms: string[]; - static installed: () => boolean; - static getPlugin: () => any; - static getPluginName: () => string; - static getPluginRef: () => string; - static getPluginInstallName: () => string; - static getSupportedPlatforms: () => string[]; - /** - * Removes existing push notifications from the notifications center - * - * @returns {Promise} Async call to native implementation - */ - clearAllNotifications(): Promise; - /** - * For Android, some notification properties are only defined programmatically. - * Channel can define the default behavior for notifications on Android 8.0+. - * Once a channel is created, it stays unchangeable until the user uninstalls the app. - * - * @param {IChannelConfiguration} channelConfig The parmeters of the new channel - * - * @returns {Promise} Async call to native implementation - */ - createNotificationChannel(channelConfig: IChannelConfiguration): Promise; - /** - * This method deletes the InstanceId, revoking all tokens. - * - * @returns {Promise} Async call to native implementation - */ - deleteInstanceId(): Promise; - /** - * Gets ios device's current APNS token - * - * @returns {Promise} Returns a Promise that resolves with the APNS token - */ - getAPNSToken(): Promise; - /** - * Retrieves the message that, on tap, opened the app - * - * @private - * - * @returns {Promise} Async call to native implementation - */ - getInitialPushPayload(): Promise; - /** - * Gets device's current registration id - * - * @returns {Promise} Returns a Promise that resolves with the registration id token - */ - getToken(): Promise; - /** - * Checking for permissions. - * - * @returns {Promise} Returns a Promise of: - * - true: push was allowed (or platform is android) - * - false: push will not be available - * - null: still not answered, recommended checking again later. - */ - hasPermission(): Promise; - /** - * Event firing when receiving new notifications - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for notification data - */ - onNotification(options?: { - once?: boolean; - }): Observable; - /** - * Event firing when receiving a new Firebase token - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for the token - */ - onTokenRefresh(options?: { - once?: boolean; - }): Observable; - /** - * Request push notification permission, alerting the user if it not have yet decided - * - * @param {IRequestPushPermissionOptions} options Options for push request - * @returns {Promise} Returns a Promise that resolves with the permission status - */ - requestPushPermission(options?: IRequestPushPermissionOptions): Promise; - /** - * Subscribes you to a [topic](https://firebase.google.com/docs/notifications/android/console-topics) - * - * @param {string} topic Topic to be subscribed to - * - * @returns {Promise} Async call to native implementation - */ - subscribeToTopic(topic: string): Promise; - /** - * Unsubscribes you from a [topic](https://firebase.google.com/docs/notifications/android/console-topics) - * - * @param {string} topic Topic to be unsubscribed from - * - * @returns {Promise} Async call to native implementation - */ - unsubscribeFromTopic(topic: string): Promise; -} diff --git a/ionic/ngx/FCM.js b/ionic/ngx/FCM.js deleted file mode 100644 index c4161eccc..000000000 --- a/ionic/ngx/FCM.js +++ /dev/null @@ -1,83 +0,0 @@ -var __decorate = - (this && this.__decorate) || - function (decorators, target, key, desc) { - var c = arguments.length, - r = - c < 3 - ? target - : desc === null - ? (desc = Object.getOwnPropertyDescriptor(target, key)) - : desc, - d - if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') - r = Reflect.decorate(decorators, target, key, desc) - else - for (var i = decorators.length - 1; i >= 0; i--) - if ((d = decorators[i])) - r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r - return c > 3 && r && Object.defineProperty(target, key, r), r - } -import { Injectable } from '@angular/core' -import { Subject } from 'rxjs' -import { IonicNativePlugin } from '@ionic-native/core' - -function FCM() {} -FCM.prototype.clearAllNotifications = function () { - return window.FCM.clearAllNotifications() -} -FCM.prototype.createNotificationChannel = function (channelConfig) { - return window.FCM.createNotificationChannel(channelConfig) -} -FCM.prototype.deleteInstanceId = function () { - return window.FCM.deleteInstanceId() -} -FCM.prototype.getAPNSToken = function () { - return window.FCM.getAPNSToken() -} -FCM.prototype.getInitialPushPayload = function () { - return window.FCM.getInitialPushPayload() -} -FCM.prototype.getToken = function () { - return window.FCM.getToken() -} -FCM.prototype.hasPermission = function () { - return window.FCM.hasPermission() -} -FCM.prototype.onNotification = function (options) { - var observable = new Subject() - var handler = function (payload) { - return observable.next(payload) - } - window.FCM.onNotification(handler, options) - return observable -} -FCM.prototype.onTokenRefresh = function (options) { - var observable = new Subject() - window.FCM.onTokenRefresh(function (token) { - return observable.next(token) - }, options) - return observable -} -FCM.prototype.requestPushPermission = function (options) { - return window.FCM.requestPushPermission(options) -} -FCM.prototype.subscribeToTopic = function (topic) { - return window.FCM.subscribeToTopic(topic) -} -FCM.prototype.unsubscribeFromTopic = function (topic) { - return window.FCM.unsubscribeFromTopic(topic) -} -FCM.pluginName = 'FCM' -FCM.plugin = 'cordova-plugin-fcm-with-dependecy-updated' -FCM.pluginRef = 'FCM' -FCM.repo = 'https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated' -FCM.platforms = ['Android', 'iOS'] -FCM.installed = IonicNativePlugin.installed -FCM.getPlugin = IonicNativePlugin.getPlugin -FCM.getPluginName = IonicNativePlugin.getPluginName -FCM.getPluginRef = IonicNativePlugin.getPluginRef -FCM.getPluginInstallName = IonicNativePlugin.getPluginInstallName -FCM.getSupportedPlatforms = IonicNativePlugin.getSupportedPlatforms -FCM = __decorate([Injectable()], FCM) - -export { FCM } diff --git a/ionic/ngx/package.json b/ionic/ngx/package.json deleted file mode 100644 index f0723fb0a..000000000 --- a/ionic/ngx/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "7.8.0", - "name": "cordova-plugin-fcm-with-dependecy-updated", - "cordova_name": "Cordova FCM Push Plugin", - "description": "Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated", - "license": "MIT", - "main": "./FCM.js", - "repo": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated", - "issue": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues", - "author": "André Augusto Tissot", - "repository": { - "type": "git", - "url": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated" - }, - "keywords": [ - "ecosystem:cordova", - "cordova-android", - "cordova-ios", - "notifications", - "push", - "firebase", - "fcm", - "ios", - "android", - "cordova", - "ionic" - ], - "platforms": ["android", "ios"], - "devDependencies": { - "@types/cordova": "0.0.34", - "prettier": "^2.0.5", - "tslint": "^6.1.2", - "tslint-microsoft-contrib": "^6.2.0", - "typescript": "^3.9.3" - }, - "dependencies": { - "@angular/core": "^9.1.9", - "@ionic-native/core": "^5.26.0", - "rxjs": "^6.5.5" - } -} diff --git a/ionic/package.json b/ionic/package.json deleted file mode 100644 index f0723fb0a..000000000 --- a/ionic/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "7.8.0", - "name": "cordova-plugin-fcm-with-dependecy-updated", - "cordova_name": "Cordova FCM Push Plugin", - "description": "Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated", - "license": "MIT", - "main": "./FCM.js", - "repo": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated", - "issue": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues", - "author": "André Augusto Tissot", - "repository": { - "type": "git", - "url": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated" - }, - "keywords": [ - "ecosystem:cordova", - "cordova-android", - "cordova-ios", - "notifications", - "push", - "firebase", - "fcm", - "ios", - "android", - "cordova", - "ionic" - ], - "platforms": ["android", "ios"], - "devDependencies": { - "@types/cordova": "0.0.34", - "prettier": "^2.0.5", - "tslint": "^6.1.2", - "tslint-microsoft-contrib": "^6.2.0", - "typescript": "^3.9.3" - }, - "dependencies": { - "@angular/core": "^9.1.9", - "@ionic-native/core": "^5.26.0", - "rxjs": "^6.5.5" - } -} diff --git a/ionic/v4/FCM.d.ts b/ionic/v4/FCM.d.ts deleted file mode 100644 index f44330f98..000000000 --- a/ionic/v4/FCM.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Observable } from 'rxjs'; -import { IChannelConfiguration } from '../../typings/IChannelConfiguration'; -import { IRequestPushPermissionOptions } from '../../typings/IRequestPushPermissionOptions'; -import { INotificationPayload } from '../../typings/INotificationPayload'; -/** - * @name FCM - * @description - * Easy plug&play push notification for Google Firebase FCM. - * - * @interfaces - * INotificationPayload - * IChannelConfiguration - * IRequestPushPermissionOptions - */ -export declare class FCM { - /** - * Removes existing push notifications from the notifications center - * - * @returns {Promise} Async call to native implementation - */ - clearAllNotifications(): Promise; - /** - * For Android, some notification properties are only defined programmatically. - * Channel can define the default behavior for notifications on Android 8.0+. - * Once a channel is created, it stays unchangeable until the user uninstalls the app. - * - * @param {IChannelConfiguration} channelConfig The parmeters of the new channel - * - * @returns {Promise} Async call to native implementation - */ - createNotificationChannel(channelConfig: IChannelConfiguration): Promise; - /** - * This method deletes the InstanceId, revoking all tokens. - * - * @returns {Promise} Async call to native implementation - */ - deleteInstanceId(): Promise; - /** - * Gets ios device's current APNS token - * - * @returns {Promise} Returns a Promise that resolves with the APNS token - */ - getAPNSToken(): Promise; - /** - * Retrieves the message that, on tap, opened the app - * - * @private - * - * @returns {Promise} Async call to native implementation - */ - getInitialPushPayload(): Promise; - /** - * Gets device's current registration id - * - * @returns {Promise} Returns a Promise that resolves with the registration id token - */ - getToken(): Promise; - /** - * Checking for permissions. - * - * @returns {Promise} Returns a Promise of: - * - true: push was allowed (or platform is android) - * - false: push will not be available - * - null: still not answered, recommended checking again later. - */ - hasPermission(): Promise; - /** - * Event firing when receiving new notifications - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for notification data - */ - onNotification(options?: { - once?: boolean; - }): Observable; - /** - * Event firing when receiving a new Firebase token - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for the token - */ - onTokenRefresh(options?: { - once?: boolean; - }): Observable; - /** - * Request push notification permission, alerting the user if it not have yet decided - * - * @param {IRequestPushPermissionOptions} options Options for push request - * @returns {Promise} Returns a Promise that resolves with the permission status - */ - requestPushPermission(options?: IRequestPushPermissionOptions): Promise; - /** - * Subscribes you to a [topic](https://firebase.google.com/docs/notifications/android/console-topics) - * - * @param {string} topic Topic to be subscribed to - * - * @returns {Promise} Async call to native implementation - */ - subscribeToTopic(topic: string): Promise; - /** - * Unsubscribes you from a [topic](https://firebase.google.com/docs/notifications/android/console-topics) - * - * @param {string} topic Topic to be unsubscribed from - * - * @returns {Promise} Async call to native implementation - */ - unsubscribeFromTopic(topic: string): Promise; -} diff --git a/ionic/v4/FCM.js b/ionic/v4/FCM.js deleted file mode 100644 index 0df5351b7..000000000 --- a/ionic/v4/FCM.js +++ /dev/null @@ -1,84 +0,0 @@ -var __decorate = - (this && this.__decorate) || - function (decorators, target, key, desc) { - var c = arguments.length, - r = - c < 3 - ? target - : desc === null - ? (desc = Object.getOwnPropertyDescriptor(target, key)) - : desc, - d - if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') - r = Reflect.decorate(decorators, target, key, desc) - else - for (var i = decorators.length - 1; i >= 0; i--) - if ((d = decorators[i])) - r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r - return c > 3 && r && Object.defineProperty(target, key, r), r - } -import { Injectable } from '@angular/core' -import { Plugin } from '@ionic-native/core' -import { Subject } from 'rxjs' - -function FCM() {} -FCM.prototype.clearAllNotifications = function () { - return window.FCM.clearAllNotifications() -} -FCM.prototype.createNotificationChannel = function (channelConfig) { - return window.FCM.createNotificationChannel(channelConfig) -} -FCM.prototype.deleteInstanceId = function () { - return window.FCM.deleteInstanceId() -} -FCM.prototype.getAPNSToken = function () { - return window.FCM.getAPNSToken() -} -FCM.prototype.getInitialPushPayload = function () { - return window.FCM.getInitialPushPayload() -} -FCM.prototype.getToken = function () { - return window.FCM.getToken() -} -FCM.prototype.hasPermission = function () { - return window.FCM.hasPermission() -} -FCM.prototype.onNotification = function (options) { - var observable = new Subject() - var handler = function (payload) { - return observable.next(payload) - } - window.FCM.onNotification(handler, options) - return observable -} -FCM.prototype.onTokenRefresh = function (options) { - var observable = new Subject() - window.FCM.onTokenRefresh(function (token) { - return observable.next(token) - }, options) - return observable -} -FCM.prototype.requestPushPermission = function (options) { - return window.FCM.requestPushPermission(options) -} -FCM.prototype.subscribeToTopic = function (topic) { - return window.FCM.subscribeToTopic(topic) -} -FCM.prototype.unsubscribeFromTopic = function (topic) { - return window.FCM.unsubscribeFromTopic(topic) -} -FCM = __decorate( - [ - Plugin({ - pluginName: 'FCM', - plugin: 'cordova-plugin-fcm-with-dependecy-updated', - pluginRef: 'FCM', - repo: 'https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated', - platforms: ['Android', 'iOS'] - }), - Injectable() - ], - FCM -) - -export { FCM } diff --git a/ionic/v4/package.json b/ionic/v4/package.json deleted file mode 100644 index f0723fb0a..000000000 --- a/ionic/v4/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "7.8.0", - "name": "cordova-plugin-fcm-with-dependecy-updated", - "cordova_name": "Cordova FCM Push Plugin", - "description": "Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated", - "license": "MIT", - "main": "./FCM.js", - "repo": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated", - "issue": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues", - "author": "André Augusto Tissot", - "repository": { - "type": "git", - "url": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated" - }, - "keywords": [ - "ecosystem:cordova", - "cordova-android", - "cordova-ios", - "notifications", - "push", - "firebase", - "fcm", - "ios", - "android", - "cordova", - "ionic" - ], - "platforms": ["android", "ios"], - "devDependencies": { - "@types/cordova": "0.0.34", - "prettier": "^2.0.5", - "tslint": "^6.1.2", - "tslint-microsoft-contrib": "^6.2.0", - "typescript": "^3.9.3" - }, - "dependencies": { - "@angular/core": "^9.1.9", - "@ionic-native/core": "^5.26.0", - "rxjs": "^6.5.5" - } -} diff --git a/plugin.xml b/plugin.xml index 183c1737c..48bc4cab4 100644 --- a/plugin.xml +++ b/plugin.xml @@ -35,22 +35,24 @@ + + - + + + - + - + @@ -78,58 +80,8 @@ - - - - - - - - - - - - development - - - production - - - - remote-notification - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/scripts/configuration.js b/scripts/configuration.js index f3b12ac85..b05854a5e 100644 --- a/scripts/configuration.js +++ b/scripts/configuration.js @@ -1,14 +1,22 @@ 'use strict'; -var helpers = require('./helpers'); +const helpers = require('./helpers'); +const configPreferences = require('./get_config_preferences').getPreferences(); -var APP_NAME = helpers.getValueFromXml( +let APP_NAME = helpers.getValueFromXml( 'config.xml', 'name', 'app name was not found on config.xml' ); -var IOS_DIR = 'platforms/ios'; -var ANDROID_DIR = 'platforms/android'; + +console.log("###### DETECTED PREFERENCES: " + JSON.stringify(configPreferences) + " ######") + +const ENV = configPreferences.common.env; + +console.log("###### USING ENV PROPERTY: " + ENV + " ######"); + +let IOS_DIR = 'platforms/ios'; +let ANDROID_DIR = 'platforms/android'; exports.PLATFORM = { IOS: { @@ -35,7 +43,11 @@ exports.PLATFORM = { ANDROID_DIR + '/google-services.json', ANDROID_DIR + '/assets/www/google-services.json', 'www/google-services.json', - 'google-services.json' + 'google-services.json', + ANDROID_DIR + '/' + ENV + '-google-services.json', + ANDROID_DIR + '/assets/www/' + ENV + '-google-services.json', + 'www/' + ENV + '-google-services.json', + ENV + '-google-services.json' ], stringsXmls: [ ANDROID_DIR + '/app/build/generated/res/google-services/debug/values/values.xml' diff --git a/scripts/copy_google_service_files.js b/scripts/copy_google_service_files.js index 2e83a77ca..6a4b05788 100644 --- a/scripts/copy_google_service_files.js +++ b/scripts/copy_google_service_files.js @@ -5,9 +5,11 @@ var fs = require('fs'); var helpers = require('./helpers'); var configurations = require(`./configuration`); + var PLATFORM = configurations.PLATFORM; function copyGoogleServiceFile(platform) { + console.log("###### FINDING GOOGLE-SERVICES FILE ######"); var googleServiceContent = helpers.getGoogleServiceContent(platform); if (!googleServiceContent) { return; @@ -43,6 +45,3 @@ function ensureDirExistance(dirPath) { if (helpers.directoryExists(PLATFORM.ANDROID.dir)) { copyGoogleServiceFile(PLATFORM.ANDROID); } -if (helpers.directoryExists(PLATFORM.IOS.dir)) { - copyGoogleServiceFile(PLATFORM.IOS); -} diff --git a/scripts/enableGoogleServicesHook.js b/scripts/enableGoogleServicesHook.js new file mode 100644 index 000000000..545596a4b --- /dev/null +++ b/scripts/enableGoogleServicesHook.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function(context) { + const gradleConfigPath = path.join(context.opts.projectRoot, 'platforms/android/cdv-gradle-config.json'); + + fs.readFile(gradleConfigPath, 'utf8', (err, data) => { + if (err) { + console.error('❌ Error reading cdv-gradle-config.json:', err); + throw err; + } + + let config = JSON.parse(data); + + if (config.IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED === false) { + config.IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED = true; + + fs.writeFile(gradleConfigPath, JSON.stringify(config, null, 2), (err) => { + if (err) { + console.error('❌ Error updating cdv-gradle-config.json:', err); + throw err; + } else { + console.log('✅ cdv-gradle-config.json updated. Google Services enabled.'); + } + }); + } else { + console.log('✅ Google Services is already set TRUE in cdv-gradle-config.json.'); + } + }); +}; diff --git a/scripts/get_config_preferences.js b/scripts/get_config_preferences.js new file mode 100644 index 000000000..a5f775d06 --- /dev/null +++ b/scripts/get_config_preferences.js @@ -0,0 +1,45 @@ +'use strict'; + +const fs = require("fs"), + et = require("elementtree"); + +exports.getPreferences = function () { + + const platformConfig = (function () { + + return { + // Parses a given file into an elementtree object + parseElementtreeSync: function (filename) { + let contents = fs.readFileSync(filename, 'utf-8'); + if (contents) { + //Windows uses the BOM. Skip the Byte Order Mark. + contents = contents.substring(contents.indexOf('<')); + } + return new et.ElementTree(et.XML(contents)); + }, + /* Retrieves all from config.xml and returns a map of preferences with platform as the key. + If any platforms are supplied, common prefs + platform prefs will be returned, otherwise just common prefs are returned. + */ + getPreferences: function (platforms) { + const configXml = this.parseElementtreeSync("config.xml"); + let prefs = { + common: {} + }; + const commonPreferences = configXml.findall('preference'); + commonPreferences.forEach(function (el, i) { + prefs.common[el.attrib.name] = el.attrib.value; + }) + platforms.forEach(function (platform) { + prefs[platform] = {}; + let platformPreferences = configXml.findall('platform[@name=\'' + platform + '\']/preference'); + platformPreferences.forEach(function (el, i) { + prefs[platform][el.attrib.name] = el.attrib.value; + }); + }); + return prefs; + } + }; + })(); + + return platformConfig.getPreferences(['android', 'ios']); +} \ No newline at end of file diff --git a/scripts/helpers.js b/scripts/helpers.js index 07d65bbdd..9b558900e 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -53,14 +53,15 @@ exports.getGoogleServiceContent = function (platform) { var googleServiceSourcePath = exports.findExistingFilePath(platform.googleServiceSources); if (!googleServiceSourcePath) { if (platform.label === 'android') { - exports.logWarning('Android-specific google-services.json file not found!'); + console.error("###### ANDROID GOOGLE SERVICES FILE NOT FOUND: " + googleServiceSourcePath + " ######"); } else { - exports.logWarning('iOS-specific GoogleService-Info.plist file not found!'); + console.error("###### iOS GOOGLE SERVICES FILE NOT FOUND: " + googleServiceSourcePath + " ######"); } return null; } try { + console.log("###### FOUND " + googleServiceSourcePath + " FIREBASE FILE ######"); return fs.readFileSync(googleServiceSourcePath).toString(); } catch (error) { exports.logError('Error on trying to read ' + googleServiceSourcePath, error); diff --git a/scripts/install_ionic_dependencies.bat b/scripts/install_ionic_dependencies.bat deleted file mode 100755 index 5d0a0b74f..000000000 --- a/scripts/install_ionic_dependencies.bat +++ /dev/null @@ -1,6 +0,0 @@ -cd node_modules -cd cordova-plugin-fcm-with-dependecy-updated -cd scripts -node install_ionic_dependencies.js ionic -node install_ionic_dependencies.js ionic/ngx -node install_ionic_dependencies.js ionic/v4 diff --git a/scripts/install_ionic_dependencies.js b/scripts/install_ionic_dependencies.js deleted file mode 100644 index 094988830..000000000 --- a/scripts/install_ionic_dependencies.js +++ /dev/null @@ -1,67 +0,0 @@ -const helpers = require('./helpers'); -const DEST_PATH = process.argv[2]; - -const shouldInstallIonicDependencies = function () { - const fs = require('fs'); - const packageFilePath = `${process.cwd()}/../../../package.json`; - if (!helpers.fileExists(packageFilePath)) { - helpers.logWarning('package.json was not found.'); - helpers.logWarning('Ionic dependencies omission cannot be safely skipped.'); - return true; - } - let packageDataString; - try { - packageDataString = fs.readFileSync(packageFilePath); - } catch (e) { - helpers.logWarning('package.json found is unreadable.', e); - helpers.logWarning('Ionic dependencies omission cannot be safely skipped.'); - return true; - } - let packageData; - try { - packageData = JSON.parse(packageDataString); - } catch (e) { - helpers.logWarning('package.json could not be parsed.', e); - helpers.logWarning('Ionic dependencies omission cannot be safely skipped.'); - return true; - } - return !!( - packageData && - packageData.dependencies && - packageData.dependencies['@ionic-native/core'] - ); -}; - -const installIonicDependencies = function () { - const path = require('path'); - const fullDestPath = `${path.dirname(process.cwd())}/${DEST_PATH}`; - try { - process.chdir(fullDestPath); - } catch (error) { - helpers.logError(`Failed change directory to ${fullDestPath}!`, error); - helpers.logError( - `Please run \`cd node_modules/cordova-plugin-fcm-with-dependecy-updated/${DEST_PATH}; npm install\` manually` - ); - return; - } - - const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'; - helpers - .execute(npm, ['install', '--loglevel', 'error', '--no-progress']) - .catch(function (e) { - helpers.logError('Failed to auto install Ionic dependencies!', e); - helpers.logError( - `Please run \`cd node_modules/cordova-plugin-fcm-with-dependecy-updated/${DEST_PATH}; npm install\` manually` - ); - }) - .then(function (output) { - console.log(`Ionic dependencies installed for ${DEST_PATH}:`); - console.log(output); - }); -}; - -if (shouldInstallIonicDependencies()) { - installIonicDependencies(); -} else { - console.log(`Ionic dependencies install skipped for ${DEST_PATH}`); -} diff --git a/src/android/FCMPlugin.gradle b/src/android/FCMPlugin.gradle index 6653cbf96..1edfea1b6 100644 --- a/src/android/FCMPlugin.gradle +++ b/src/android/FCMPlugin.gradle @@ -64,8 +64,10 @@ repositories { if (gradleNumberVersion >= 3.4f) { google() } + maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" } } dependencies { + implementation "com.salesforce.marketingcloud:marketingcloudsdk:8.0.6" // Load system enviroment defined values, or, if unavailable, plugin defaults def ANDROID_FCM_VERSION = System.getenv('ANDROID_FCM_VERSION') ?: '21.0.0' def ANDROID_FIREBASE_BOM_VERSION = System.getenv('ANDROID_FIREBASE_BOM_VERSION') ?: '26.0.0' @@ -106,6 +108,6 @@ dependencies { } // apply plugin: 'com.google.gms.google-services' // class must be used instead of id(string) to be able to apply plugin from non-root gradle file -if (!project.plugins.hasPlugin('com.google.gms.google-services')) { - apply plugin: com.google.gms.googleservices.GoogleServicesPlugin -} +// if (!project.plugins.hasPlugin('com.google.gms.google-services')) { +// apply plugin: com.google.gms.googleservices.GoogleServicesPlugin +// } diff --git a/src/android/com/gae/scaffolder/plugin/FCMPlugin.java b/src/android/com/gae/scaffolder/plugin/FCMPlugin.java index 08e335d36..691182e26 100644 --- a/src/android/com/gae/scaffolder/plugin/FCMPlugin.java +++ b/src/android/com/gae/scaffolder/plugin/FCMPlugin.java @@ -1,23 +1,14 @@ package com.gae.scaffolder.plugin; -import androidx.core.app.NotificationManagerCompat; import android.app.NotificationManager; import android.content.Context; +import android.text.TextUtils; import android.util.Log; - -import com.gae.scaffolder.plugin.interfaces.*; -import com.google.android.gms.tasks.OnCompleteListener; -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.Task; -import com.google.firebase.iid.FirebaseInstanceId; -import com.google.firebase.iid.InstanceIdResult; +import androidx.core.app.NotificationManagerCompat; +import com.gae.scaffolder.plugin.interfaces.TokenListeners; +import com.google.firebase.installations.FirebaseInstallations; import com.google.firebase.messaging.FirebaseMessaging; - -import org.apache.cordova.CallbackContext; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.CordovaPlugin; -import org.apache.cordova.CordovaWebView; -import org.apache.cordova.PluginResult; +import org.apache.cordova.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -179,44 +170,36 @@ public void getInitialPushPayload(CallbackContext callback) { public void getToken(final TokenListeners callback) { try { - FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(Task task) { - if (!task.isSuccessful()) { - Log.w(TAG, "getInstanceId failed", task.getException()); - try { - callback.error(exceptionToJson(task.getException())); - } - catch (JSONException jsonErr) { - Log.e(TAG, "Error when parsing json", jsonErr); - } - return; - } - - // Get new Instance ID token - String newToken = task.getResult().getToken(); - - Log.i(TAG, "\tToken: " + newToken); - callback.success(newToken); - } - }); - - FirebaseInstanceId.getInstance().getInstanceId().addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(final Exception e) { - try { - Log.e(TAG, "Error retrieving token: ", e); - callback.error(exceptionToJson(e)); - } catch (JSONException jsonErr) { - Log.e(TAG, "Error when parsing json", jsonErr); - } + FirebaseMessaging.getInstance().getToken().addOnSuccessListener(token -> { + if (!TextUtils.isEmpty(token)) { + Log.d(TAG, "retrieve token successful : " + token); + callback.success(token); + } else{ + Log.w(TAG, "token should not be null..."); } + }).addOnFailureListener(e -> { + try { + callback.error(exceptionToJson(e)); + } catch (JSONException jsonException) { + jsonException.printStackTrace(); + } + }).addOnCanceledListener(() -> { + try { + callback.error(new JSONObject().put("message", "Gettoken cancelled")); + } catch (JSONException e) { + e.printStackTrace(); + } + }).addOnCompleteListener(task ->{ + Log.v(TAG, "getToken : " + task.getResult()); + callback.success(task.getResult()); }); } catch (Exception e) { Log.w(TAG, "\tError retrieving token", e); try { callback.error(exceptionToJson(e)); - } catch(JSONException je) {} + } catch(JSONException je) { + e.printStackTrace(); + } } } @@ -224,7 +207,7 @@ private void deleteInstanceId(final CallbackContext callbackContext) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { - FirebaseInstanceId.getInstance().deleteInstanceId(); + FirebaseInstallations.getInstance().delete(); callbackContext.success(); } catch (Exception e) { callbackContext.error(e.getMessage()); diff --git a/src/android/com/gae/scaffolder/plugin/MyFirebaseMessagingService.java b/src/android/com/gae/scaffolder/plugin/MyFirebaseMessagingService.java index 072d755bf..1546abf64 100644 --- a/src/android/com/gae/scaffolder/plugin/MyFirebaseMessagingService.java +++ b/src/android/com/gae/scaffolder/plugin/MyFirebaseMessagingService.java @@ -1,64 +1,110 @@ package com.gae.scaffolder.plugin; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; -import android.media.RingtoneManager; -import android.net.Uri; +import android.os.Build; import android.util.Log; -import java.util.Map; -import java.util.HashMap; - +import androidx.annotation.NonNull; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; +import com.meawallet.mtp.*; +import com.salesforce.marketingcloud.MarketingCloudSdk; +import com.salesforce.marketingcloud.messages.push.PushMessageManager; + +import java.util.HashMap; +import java.util.Map; public class MyFirebaseMessagingService extends FirebaseMessagingService { - private static final String TAG = "FCMPlugin"; + private static final String TAG = "FCMPlugin"; - @Override - public void onNewToken(String token) { - super.onNewToken(token); - Log.d(TAG, "New token: " + token); - FCMPlugin.sendTokenRefresh(token); - } + @Override + public void onNewToken(@NonNull String token) { + super.onNewToken(token); + Log.d(TAG, "New Firebase token: " + token); + FCMPlugin.sendTokenRefresh(token); + MarketingCloudSdk.requestSdk(marketingCloudSdk -> marketingCloudSdk.getPushMessageManager().setPushToken(token)); + } - /** - * Called when message is received. - * - * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. - */ - // [START receive_message] - @Override - public void onMessageReceived(RemoteMessage remoteMessage) { - // TODO(developer): Handle FCM messages here. - // If the application is in the foreground handle both data and notification messages here. - // Also if you intend on generating your own notifications as a result of a received FCM - // message, here is where that should be initiated. See sendNotification method below. - Log.d(TAG, "==> MyFirebaseMessagingService onMessageReceived"); - - if(remoteMessage.getNotification() != null){ - Log.d(TAG, "\tNotification Title: " + remoteMessage.getNotification().getTitle()); - Log.d(TAG, "\tNotification Message: " + remoteMessage.getNotification().getBody()); - } - - Map data = new HashMap(); - data.put("wasTapped", false); - - if(remoteMessage.getNotification() != null){ - data.put("title", remoteMessage.getNotification().getTitle()); - data.put("body", remoteMessage.getNotification().getBody()); - } + /** + * Called when message is received. + * + * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. + */ + @Override + public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { + Log.d(TAG, "==> MyFirebaseMessagingService onMessageReceived"); - for (String key : remoteMessage.getData().keySet()) { - Object value = remoteMessage.getData().get(key); - Log.d(TAG, "\tKey: " + key + " Value: " + value); - data.put(key, value); + if (PushMessageManager.isMarketingCloudPush(remoteMessage)) { + MarketingCloudSdk.requestSdk(marketingCloudSdk -> marketingCloudSdk.getPushMessageManager().handleMessage(remoteMessage)); + } else { + try { + Map messageData = remoteMessage.getData(); + if (MeaTokenPlatform.Rns.isMeaRemoteMessage(messageData)) { + if (MeaTokenPlatform.Rns.isMeaTransactionMessage(messageData)) { + MeaTransactionMessage transactionMessage = MeaTokenPlatform.Rns.parseTransactionMessage(messageData); + String transactionPushMessage = + "Pagamento " + transactionMessage.getAuthorizationStatus() + + "\nValor " + transactionMessage.getAmount() + " " + transactionMessage.getCurrencyCode(); +// buildNotification("MEA_TRANSACTION_NOTIFICATION", "Continente Pay", transactionPushMessage); + } else { + MeaTokenPlatform.Rns.onMessageReceived(messageData); + } } - - Log.d(TAG, "\tNotification Data: " + data.toString()); - FCMPlugin.sendPushPayload(data); + FCMPlugin.sendPushPayload(buildNotificationData(remoteMessage)); + } catch (NotInitializedException | InvalidInputException | NotRegisteredException | MeaCardException | MeaException e) { + e.printStackTrace(); + } + } + } + + private Map buildNotificationData(RemoteMessage remoteMessage) { + Map data = new HashMap<>(); + + for (String key : remoteMessage.getData().keySet()) { + Object value = remoteMessage.getData().get(key); + data.put(key, value); + } + Log.d(TAG, "\tNotification Data: " + data); + return data; + } +/* + private void buildNotification(String channel, String title, String message) { + + Intent intent = new Intent(this, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); + + createNotificationChannel(this, channel); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channel) + .setPriority(NotificationCompat.PRIORITY_HIGH) + .setSmallIcon(R.drawable.apdu_service_banner) + .setContentTitle(title) + .setContentText(message) + .setContentIntent(pendingIntent) + .setAutoCancel(true); + + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); + notificationManager.notify(69, builder.build()); + } + + private void createNotificationChannel(Context context, String channelId) { + // Create the NotificationChannel, but only on API 26+ because + // the NotificationChannel class is new and not in the support library + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH); + channel.setDescription(channelId); + // Register the channel with the system; it's not possible to change the importance + // or other notification behaviors after this + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); } - // [END receive_message] + } + */ } diff --git a/src/ionic/FCM.ts b/src/ionic/FCM.ts deleted file mode 100644 index 7a013b67c..000000000 --- a/src/ionic/FCM.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { Observable, Subject } from 'rxjs' -import { INotificationPayload } from '../../typings/INotificationPayload' -import { FCMPlugin } from '../www/FCMPlugin' -import { IRequestPushPermissionOptions } from '../../typings/IRequestPushPermissionOptions' -import { IChannelConfiguration } from '../../typings/IChannelConfiguration' - -declare namespace window { - export let FCM: FCMPlugin -} - -/** @copyFrom typings/FCMPlugin.d.ts FCMPlugin */ -export class FCMPluginOnIonic { - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin clearAllNotifications */ - public clearAllNotifications(): Promise { - return window.FCM.clearAllNotifications() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin createNotificationChannel */ - public createNotificationChannel(channelConfig: IChannelConfiguration): Promise { - return window.FCM.createNotificationChannel(channelConfig) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin deleteInstanceId */ - public deleteInstanceId(): Promise { - return window.FCM.deleteInstanceId() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getAPNSToken */ - public getAPNSToken(): Promise { - return window.FCM.getAPNSToken() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getInitialPushPayload */ - public getInitialPushPayload(): Promise { - return window.FCM.getInitialPushPayload() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getToken */ - public getToken(): Promise { - return window.FCM.getToken() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin hasPermission */ - public hasPermission(): Promise { - return window.FCM.hasPermission() - } - - /** - * Event firing when receiving new notifications - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for notification data - */ - public onNotification(options?: { once?: boolean }): Observable { - const observable = new Subject() - const handler = (payload: INotificationPayload) => observable.next(payload) - window.FCM.onNotification(handler, options) - - return observable - } - - /** - * Event firing when receiving a new Firebase token - * - * @argument {{ once?: boolean }} options once defines if the listener is only trigger once - * @returns {Observable} An object to listen for the token - */ - public onTokenRefresh(options?: { once?: boolean }): Observable { - const observable = new Subject() - window.FCM.onTokenRefresh((token: string) => observable.next(token), options) - - return observable - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin requestPushPermission */ - public requestPushPermission(options?: IRequestPushPermissionOptions): Promise { - return window.FCM.requestPushPermission(options) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin subscribeToTopic */ - public subscribeToTopic(topic: string): Promise { - return window.FCM.subscribeToTopic(topic) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin unsubscribeFromTopic */ - public unsubscribeFromTopic(topic: string): Promise { - return window.FCM.unsubscribeFromTopic(topic) - } -} - -export const FCM = new FCMPluginOnIonic() diff --git a/src/ionic/ngx/FCM.ts b/src/ionic/ngx/FCM.ts deleted file mode 100644 index 808003f45..000000000 --- a/src/ionic/ngx/FCM.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { Injectable } from '@angular/core' -import { Observable, Subject } from 'rxjs' -import { IonicNativePlugin } from '@ionic-native/core' -import type { FCMPlugin } from '../../www/FCMPlugin' -import type { IChannelConfiguration } from '../../www/IChannelConfiguration' -import type { INotificationPayload } from '../../www/INotificationPayload' -import type { IRequestPushPermissionOptions } from '../../www/IRequestPushPermissionOptions' - -declare namespace window { - export let FCM: FCMPlugin -} - -/** @copyFrom typings/FCMPlugin.d.ts FCMPlugin */ -@Injectable() -export class FCM { - public static pluginName: string = 'FCM' - public static plugin: string = 'cordova-plugin-fcm-with-dependecy-updated' - public static pluginRef: string = 'FCM' - public static repo: string = - 'https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated' - public static platforms: string[] = ['Android', 'iOS'] - public static installed: () => boolean = IonicNativePlugin.installed - public static getPlugin: () => any = IonicNativePlugin.getPlugin - public static getPluginName: () => string = IonicNativePlugin.getPluginName - public static getPluginRef: () => string = IonicNativePlugin.getPluginRef - public static getPluginInstallName: () => string = IonicNativePlugin.getPluginInstallName - public static getSupportedPlatforms: () => string[] = IonicNativePlugin.getSupportedPlatforms - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin clearAllNotifications */ - public clearAllNotifications(): Promise { - return window.FCM.clearAllNotifications() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin createNotificationChannel */ - public createNotificationChannel(channelConfig: IChannelConfiguration): Promise { - return window.FCM.createNotificationChannel(channelConfig) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin deleteInstanceId */ - public deleteInstanceId(): Promise { - return window.FCM.deleteInstanceId() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getAPNSToken */ - public getAPNSToken(): Promise { - return window.FCM.getAPNSToken() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getInitialPushPayload */ - public getInitialPushPayload(): Promise { - return window.FCM.getInitialPushPayload() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getToken */ - public getToken(): Promise { - return window.FCM.getToken() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin hasPermission */ - public hasPermission(): Promise { - return window.FCM.hasPermission() - } - - /** @copyFrom ionic/FCM.d.ts FCMPluginOnIonic onNotification */ - public onNotification(options?: { once?: boolean }): Observable { - const observable = new Subject() - const handler = (payload: INotificationPayload) => observable.next(payload) - window.FCM.onNotification(handler, options) - - return observable - } - - /** @copyFrom ionic/FCM.d.ts FCMPluginOnIonic onTokenRefresh */ - public onTokenRefresh(options?: { once?: boolean }): Observable { - const observable = new Subject() - window.FCM.onTokenRefresh((token: string) => observable.next(token), options) - - return observable - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin requestPushPermission */ - public requestPushPermission(options?: IRequestPushPermissionOptions): Promise { - return window.FCM.requestPushPermission(options) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin subscribeToTopic */ - public subscribeToTopic(topic: string): Promise { - return window.FCM.subscribeToTopic(topic) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin unsubscribeFromTopic */ - public unsubscribeFromTopic(topic: string): Promise { - return window.FCM.unsubscribeFromTopic(topic) - } -} diff --git a/src/ionic/package-lock.json b/src/ionic/package-lock.json deleted file mode 100644 index e917d1d32..000000000 --- a/src/ionic/package-lock.json +++ /dev/null @@ -1,404 +0,0 @@ -{ - "name": "cordova-plugin-fcm-with-dependecy-updated", - "version": "7.8.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@angular/core": { - "version": "11.0.4", - "resolved": "https://registry.npmjs.org/@angular/core/-/core-11.0.4.tgz", - "integrity": "sha512-860cTMjdCHcvEsHOsTzpg5rThxwVgtnY4yT0SgboWiphrlzX+aNoyN/cCJHxWhmOTRlrl6/+hkeRq95E2BZkKw==", - "requires": { - "tslib": "^2.0.0" - } - }, - "@babel/code-frame": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz", - "integrity": "sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg==", - "dev": true, - "requires": { - "@babel/highlight": "^7.10.4" - } - }, - "@babel/helper-validator-identifier": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz", - "integrity": "sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw==", - "dev": true - }, - "@babel/highlight": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.10.4.tgz", - "integrity": "sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA==", - "dev": true, - "requires": { - "@babel/helper-validator-identifier": "^7.10.4", - "chalk": "^2.0.0", - "js-tokens": "^4.0.0" - } - }, - "@ionic-native/core": { - "version": "5.30.0", - "resolved": "https://registry.npmjs.org/@ionic-native/core/-/core-5.30.0.tgz", - "integrity": "sha512-UkktFoSOAt/lgsc1nxnwjCul29yD06qHNjyv7/K7JxhqeJrqPBKihnkLu7OTAe52KdFBozRxLKDP6HWcGderqA==", - "requires": { - "@types/cordova": "^0.0.34" - }, - "dependencies": { - "@types/cordova": { - "version": "0.0.34", - "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", - "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=" - } - } - }, - "@types/cordova": { - "version": "0.0.34", - "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", - "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=", - "dev": true - }, - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, - "requires": { - "sprintf-js": "~1.0.2" - } - }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "builtin-modules": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", - "dev": true - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true - }, - "js-yaml": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz", - "integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - } - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", - "dev": true - }, - "prettier": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.2.1.tgz", - "integrity": "sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==", - "dev": true - }, - "resolve": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", - "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } - }, - "rxjs": { - "version": "6.6.3", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.3.tgz", - "integrity": "sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==", - "requires": { - "tslib": "^1.9.0" - }, - "dependencies": { - "tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" - } - } - }, - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true - }, - "sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, - "tslib": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.0.3.tgz", - "integrity": "sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==" - }, - "tslint": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-6.1.3.tgz", - "integrity": "sha512-IbR4nkT96EQOvKE2PW/djGz8iGNeJ4rF2mBfiYaR/nvUWYKJhLwimoJKgjIFEIDibBtOevj7BqCRL4oHeWWUCg==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.0.0", - "builtin-modules": "^1.1.1", - "chalk": "^2.3.0", - "commander": "^2.12.1", - "diff": "^4.0.1", - "glob": "^7.1.1", - "js-yaml": "^3.13.1", - "minimatch": "^3.0.4", - "mkdirp": "^0.5.3", - "resolve": "^1.3.2", - "semver": "^5.3.0", - "tslib": "^1.13.0", - "tsutils": "^2.29.0" - }, - "dependencies": { - "tslib": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", - "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", - "dev": true - } - } - }, - "tslint-microsoft-contrib": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/tslint-microsoft-contrib/-/tslint-microsoft-contrib-6.2.0.tgz", - "integrity": "sha512-6tfi/2tHqV/3CL77pULBcK+foty11Rr0idRDxKnteTaKm6gWF9qmaCNU17HVssOuwlYNyOmd9Jsmjd+1t3a3qw==", - "dev": true, - "requires": { - "tsutils": "^2.27.2 <2.29.0" - }, - "dependencies": { - "tsutils": { - "version": "2.28.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.28.0.tgz", - "integrity": "sha512-bh5nAtW0tuhvOJnx1GLRn5ScraRLICGyJV5wJhtRWOLsxW70Kk5tZtpK3O/hW6LDnqKS9mlUMPZj9fEMJ0gxqA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - }, - "dependencies": { - "tslib": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", - "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", - "dev": true - } - } - } - } - }, - "tsutils": { - "version": "2.29.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", - "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - }, - "dependencies": { - "tslib": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", - "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", - "dev": true - } - } - }, - "typescript": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", - "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", - "dev": true - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - } - } -} diff --git a/src/ionic/package.json b/src/ionic/package.json deleted file mode 100644 index a7771b596..000000000 --- a/src/ionic/package.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "version": "7.8.0", - "name": "cordova-plugin-fcm-with-dependecy-updated", - "cordova_name": "Cordova FCM Push Plugin", - "description": "Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated", - "license": "MIT", - "main": "./FCMPluginOnIonic.js", - "repo": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated", - "issue": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues", - "author": "André Augusto Tissot", - "scripts": { - "build": "npm run build:before;npm run build:dts;npm run build:js;npm run build:after", - "build:before": "rm -rf ../../ionic;mkdir -p ../../ionic/ngx;mkdir -p ../../ionic/v4", - "build:js": "./scripts/build.js.sh", - "build:dts": "./scripts/build.dts.sh", - "build:after": "cd ../../ionic;rm -rf ionic;rm -rf www", - "tsc": "npx tsc -p . --noEmit" - }, - "repository": { - "type": "git", - "url": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated" - }, - "keywords": [ - "ecosystem:cordova", - "cordova-android", - "cordova-ios", - "notifications", - "push", - "firebase", - "fcm", - "ios", - "android", - "cordova", - "ionic" - ], - "platforms": [ - "android", - "ios" - ], - "dependencies": { - "@angular/core": "^11.0.4", - "@ionic-native/core": "^5.30.0", - "rxjs": "^6.6.3" - }, - "devDependencies": { - "@types/cordova": "0.0.34", - "prettier": "^2.2.1", - "tslint": "^6.1.3", - "tslint-microsoft-contrib": "^6.2.0", - "typescript": "^4.1.2" - } -} diff --git a/src/ionic/package.toCopy.json b/src/ionic/package.toCopy.json deleted file mode 100644 index f0723fb0a..000000000 --- a/src/ionic/package.toCopy.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "7.8.0", - "name": "cordova-plugin-fcm-with-dependecy-updated", - "cordova_name": "Cordova FCM Push Plugin", - "description": "Google Firebase Cloud Messaging Cordova Push Plugin fork with dependecy updated", - "license": "MIT", - "main": "./FCM.js", - "repo": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated", - "issue": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues", - "author": "André Augusto Tissot", - "repository": { - "type": "git", - "url": "https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated" - }, - "keywords": [ - "ecosystem:cordova", - "cordova-android", - "cordova-ios", - "notifications", - "push", - "firebase", - "fcm", - "ios", - "android", - "cordova", - "ionic" - ], - "platforms": ["android", "ios"], - "devDependencies": { - "@types/cordova": "0.0.34", - "prettier": "^2.0.5", - "tslint": "^6.1.2", - "tslint-microsoft-contrib": "^6.2.0", - "typescript": "^3.9.3" - }, - "dependencies": { - "@angular/core": "^9.1.9", - "@ionic-native/core": "^5.26.0", - "rxjs": "^6.5.5" - } -} diff --git a/src/ionic/scripts/build.dts.sh b/src/ionic/scripts/build.dts.sh deleted file mode 100755 index 44a289611..000000000 --- a/src/ionic/scripts/build.dts.sh +++ /dev/null @@ -1,42 +0,0 @@ -## Generate .d.ts files -tsc -p . --declaration true --removeComments false - -## Fix root .d.ts files -cd ../../ionic -sed 's/\.\.\/\.\.\/typings\//\.\.\/typings\//' ionic/FCM.d.ts > ionic/FCM.tmp.d.ts -sed 's/\.\.\/www\//\.\.\/typings\//' ionic/FCM.tmp.d.ts > FCM.d.ts -cp ../src/ionic/package.toCopy.json package.json - -## Fix ngx .d.ts files -sed 's/\.\.\/www\//\.\.\/typings\//' ionic/ngx/FCM.d.ts > ngx/FCM.d.ts -cp ../src/ionic/package.toCopy.json ngx/package.json - -## Fix v4 .d.ts files -mv ionic/v4/*.d.ts ./v4/ -sed 's/\.\.\/\.\.\/typings\//\.\.\/typings\//' v4/FCM.d.ts > v4/FCM.tmp.d.ts -mv v4/FCM.tmp.d.ts v4/FCM.d.ts -cp ../src/ionic/package.toCopy.json v4/package.json - -## Replace copyFrom with source value -cd .. -source "src/ionic/scripts/replaceCopyFromOnFile.helper.sh" -replaceCopyFromOnFile ionic/FCM.d.ts -replaceCopyFromOnFile ionic/ngx/FCM.d.ts -replaceCopyFromOnFile ionic/v4/FCM.d.ts - -## Remove empty lines -sed '/^[[:space:]]*$/d' ionic/FCM.d.ts > ionic/FCM.d.ts.tmp -mv ionic/FCM.d.ts.tmp ionic/FCM.d.ts -sed '/^[[:space:]]*$/d' ionic/ngx/FCM.d.ts > ionic/ngx/FCM.d.ts.tmp -mv ionic/ngx/FCM.d.ts.tmp ionic/ngx/FCM.d.ts -sed '/^[[:space:]]*$/d' ionic/v4/FCM.d.ts > ionic/v4/FCM.d.ts.tmp -mv ionic/v4/FCM.d.ts.tmp ionic/v4/FCM.d.ts - -## Simplify imports -simplifyImports() { - filePath="$1" - sed 's/import type /import /g' "$filePath" > "$filePath.tmp" - mv "$filePath.tmp" "$filePath" -} -simplifyImports ionic/v4/FCM.d.ts -simplifyImports ionic/ngx/FCM.d.ts \ No newline at end of file diff --git a/src/ionic/scripts/build.js.sh b/src/ionic/scripts/build.js.sh deleted file mode 100755 index 4b96148a5..000000000 --- a/src/ionic/scripts/build.js.sh +++ /dev/null @@ -1,29 +0,0 @@ -## Build JS files -tsc -p . --declaration false --removeComments true - -## Move files to the correct directories -cd ../../ionic -mv ionic/*.js . -mv ionic/ngx/*.js ./ngx/ -mv ionic/v4/*.js ./v4/ - -## Simplify main build -sed 's/var FCMPluginOnIonic = (function () {//' FCM.js > FCM.js.tmp -sed 's/}());//' FCM.js.tmp > FCM.js -sed 's/return FCMPluginOnIonic;//' FCM.js > FCM.js.tmp -mv FCM.js.tmp FCM.js -npx prettier FCM.js --write - -## Simplify v4 build -sed 's/var FCM = (function () {//' v4/FCM.js > v4/FCM.js.tmp -sed 's/}());//' v4/FCM.js.tmp > v4/FCM.js -sed 's/return FCM;//' v4/FCM.js > v4/FCM.js.tmp -mv v4/FCM.js.tmp v4/FCM.js -npx prettier v4/FCM.js --write - -## Simplify ngx build -sed 's/var FCM = (function () {//' ngx/FCM.js > ngx/FCM.js.tmp -sed 's/}());//' ngx/FCM.js.tmp > ngx/FCM.js -sed 's/return FCM;//' ngx/FCM.js > ngx/FCM.js.tmp -mv ngx/FCM.js.tmp ngx/FCM.js -npx prettier ngx/FCM.js --write diff --git a/src/ionic/scripts/replaceCopyFromOnFile.helper.sh b/src/ionic/scripts/replaceCopyFromOnFile.helper.sh deleted file mode 100755 index c1e4dd2b8..000000000 --- a/src/ionic/scripts/replaceCopyFromOnFile.helper.sh +++ /dev/null @@ -1,27 +0,0 @@ -source "src/ionic/scripts/retriveJSDocFromFileClass.helper.sh" -source "src/ionic/scripts/retriveJSDocFromFileClassMethod.helper.sh" - -replaceCopyFromOnFile() { - filePath="$1" - fileTextOut="" - SAFE_IFS=IFS - while IFS= read -r fileLine; do - if [[ ! "$fileLine" == *"/** @copyFrom "* ]]; then - fileTextOut+="$fileLine\n" - continue - fi - targetFilePath=$(echo "$fileLine" | xargs | cut -d ' ' -f 3) - className=$(echo "$fileLine" | xargs | cut -d ' ' -f 4) - methodName=$(echo "$fileLine" | xargs | cut -d ' ' -f 5) - if [[ "$methodName" == "*/" ]]; then - fileTextOut+=$(retriveJSDocFromFileClass "$targetFilePath" "$className")"\n" - else - fileTextOut+=$(retriveJSDocFromFileClassMethod "$targetFilePath" "$className" "$methodName")"\n" - fi - done < "$filePath" - IFS=SAFE_IFS - echo "$fileTextOut" > "$filePath.tmp" - mv "$filePath.tmp" "$filePath" -} - -export -f replaceCopyFromOnFile \ No newline at end of file diff --git a/src/ionic/scripts/retriveJSDocFromFileClass.helper.sh b/src/ionic/scripts/retriveJSDocFromFileClass.helper.sh deleted file mode 100755 index dac8668e0..000000000 --- a/src/ionic/scripts/retriveJSDocFromFileClass.helper.sh +++ /dev/null @@ -1,24 +0,0 @@ -retriveJSDocFromFileClass() { - filePath="$1" - className="$2" - buffer="" - bufferEnabled="" - while IFS= read -r fileLine; do - if [[ "$fileLine" == *"class $className "* ]]; then - echo "$buffer" - fi - if [[ "$fileLine" == *"/**"* ]]; then - bufferEnabled="TRUE" - buffer="" - fi - if [[ ! "$bufferEnabled" ]]; then - continue - fi - buffer+="$fileLine\n" - if [[ "$fileLine" == *"*/"* ]]; then - bufferEnabled="" - fi - done < "$filePath" -} - -export -f retriveJSDocFromFileClass \ No newline at end of file diff --git a/src/ionic/scripts/retriveJSDocFromFileClassMethod.helper.sh b/src/ionic/scripts/retriveJSDocFromFileClassMethod.helper.sh deleted file mode 100755 index 7f64bb0c8..000000000 --- a/src/ionic/scripts/retriveJSDocFromFileClassMethod.helper.sh +++ /dev/null @@ -1,32 +0,0 @@ -retriveJSDocFromFileClassMethod() { - filePath="$1" - className="$2" - methodName="$3" - classFound="" - buffer="" - bufferEnabled="" - while IFS= read -r fileLine; do - if [[ "$fileLine" == *"class $className "* ]]; then - classFound="TRUE" - fi - if [[ ! "$classFound" ]]; then - continue - fi - if [[ "$fileLine" == *"$methodName"* ]]; then - echo "$buffer" - fi - if [[ "$fileLine" == *"/**"* ]]; then - bufferEnabled="TRUE" - buffer="" - fi - if [[ ! "$bufferEnabled" ]]; then - continue - fi - buffer+="$fileLine\n" - if [[ "$fileLine" == *"*/"* ]]; then - bufferEnabled="" - fi - done < "$filePath" -} - -export -f retriveJSDocFromFileClassMethod \ No newline at end of file diff --git a/src/ionic/tsconfig.json b/src/ionic/tsconfig.json deleted file mode 100644 index b93b455f6..000000000 --- a/src/ionic/tsconfig.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "compilerOptions": { - "alwaysStrict": true, - "baseUrl": ".", - "esModuleInterop": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "lib": ["es2015", "dom"], - "module": "es2015", - "moduleResolution": "node", - "outDir": "../../ionic", - "strictNullChecks": true, - "strictPropertyInitialization": true, - "target": "es5" - }, - "include": ["./**/*.ts"], - "exclude": ["node_modules"] -} diff --git a/src/ionic/v4/FCM.ts b/src/ionic/v4/FCM.ts deleted file mode 100644 index 0111307b8..000000000 --- a/src/ionic/v4/FCM.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { Injectable } from '@angular/core' -import { Plugin } from '@ionic-native/core' -import { Observable, Subject } from 'rxjs' -import type { FCMPlugin } from '../../../typings/FCMPlugin' -import type { IChannelConfiguration } from '../../../typings/IChannelConfiguration' -import type { IRequestPushPermissionOptions } from '../../../typings/IRequestPushPermissionOptions' -import type { INotificationPayload } from '../../../typings/INotificationPayload' - -declare namespace window { - export let FCM: FCMPlugin -} - -/** @copyFrom typings/FCMPlugin.d.ts FCMPlugin */ -@Plugin({ - pluginName: 'FCM', - plugin: 'cordova-plugin-fcm-with-dependecy-updated', - pluginRef: 'FCM', - repo: 'https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated', - platforms: ['Android', 'iOS'], -}) -@Injectable() -export class FCM { - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin clearAllNotifications */ - public clearAllNotifications(): Promise { - return window.FCM.clearAllNotifications() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin createNotificationChannel */ - public createNotificationChannel(channelConfig: IChannelConfiguration): Promise { - return window.FCM.createNotificationChannel(channelConfig) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin deleteInstanceId */ - public deleteInstanceId(): Promise { - return window.FCM.deleteInstanceId() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getAPNSToken */ - public getAPNSToken(): Promise { - return window.FCM.getAPNSToken() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getInitialPushPayload */ - public getInitialPushPayload(): Promise { - return window.FCM.getInitialPushPayload() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin getToken */ - public getToken(): Promise { - return window.FCM.getToken() - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin hasPermission */ - public hasPermission(): Promise { - return window.FCM.hasPermission() - } - - /** @copyFrom ionic/FCM.d.ts FCMPluginOnIonic onNotification */ - public onNotification(options?: { once?: boolean }): Observable { - const observable = new Subject() - const handler = (payload: INotificationPayload) => observable.next(payload) - window.FCM.onNotification(handler, options) - - return observable - } - - /** @copyFrom ionic/FCM.d.ts FCMPluginOnIonic onTokenRefresh */ - public onTokenRefresh(options?: { once?: boolean }): Observable { - const observable = new Subject() - window.FCM.onTokenRefresh((token: string) => observable.next(token), options) - - return observable - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin requestPushPermission */ - public requestPushPermission(options?: IRequestPushPermissionOptions): Promise { - return window.FCM.requestPushPermission(options) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin subscribeToTopic */ - public subscribeToTopic(topic: string): Promise { - return window.FCM.subscribeToTopic(topic) - } - - /** @copyFrom typings/FCMPlugin.d.ts FCMPlugin unsubscribeFromTopic */ - public unsubscribeFromTopic(topic: string): Promise { - return window.FCM.unsubscribeFromTopic(topic) - } -} diff --git a/src/ios/AppDelegate+FCMPlugin.h b/src/ios/AppDelegate+FCMPlugin.h deleted file mode 100644 index d1d991660..000000000 --- a/src/ios/AppDelegate+FCMPlugin.h +++ /dev/null @@ -1,17 +0,0 @@ -#import "AppDelegate.h" -#import -#import - -@interface AppDelegate (FCMPlugin) - -+ (NSData*)getLastPush; -+ (NSData*)getInitialPushPayload; -+ (NSString*)getFCMToken; -+ (NSString*)getAPNSToken; -+ (void)deleteInstanceId:(void (^)(NSError *error))handler; -+ (void)setLastPush:(NSData*)push; -+ (void)setInitialPushPayload:(NSData*)payload; -+ (void)requestPushPermission:(void (^)(BOOL yesOrNo, NSError* error))block withOptions:(NSDictionary*)options; -+ (void)hasPushPermission:(void (^)(NSNumber* yesNoOrNil))block; - -@end diff --git a/src/ios/AppDelegate+FCMPlugin.m b/src/ios/AppDelegate+FCMPlugin.m deleted file mode 100644 index 0cef55cf8..000000000 --- a/src/ios/AppDelegate+FCMPlugin.m +++ /dev/null @@ -1,253 +0,0 @@ -#import "AppDelegate+FCMPlugin.h" -#import "FCMPlugin.h" -#import "FCMPluginIOS9Support.h" -#import "FCMNotificationCenterDelegate.h" -#import -#import - -@import UserNotifications; -@import Firebase; - -// Implement UNUserNotificationCenterDelegate to receive display notification via APNS for devices -// running iOS 10 and above. Implement FIRMessagingDelegate to receive data message via FCM for -// devices running iOS 10 and above. -@interface AppDelegate () -@end - -@implementation AppDelegate (MCPlugin) - -static NSData *lastPush; -static NSData *initialPushPayload; -static NSString *fcmToken; -static NSString *apnsToken; -NSString *const kGCMMessageIDKey = @"gcm.message_id"; -FCMNotificationCenterDelegate *notificationCenterDelegate; - -//Method swizzling -+ (void)load { - Method original = class_getInstanceMethod(self, @selector(application:didFinishLaunchingWithOptions:)); - Method custom = class_getInstanceMethod(self, @selector(application:customDidFinishLaunchingWithOptions:)); - method_exchangeImplementations(original, custom); -} - -- (BOOL)application:(UIApplication *)application customDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [self application:application customDidFinishLaunchingWithOptions:launchOptions]; - - NSLog(@"DidFinishLaunchingWithOptions"); - if ([UNUserNotificationCenter class] != nil) { - // For iOS 10 display notification (sent via APNS) - notificationCenterDelegate = [NSClassFromString(@"FCMNotificationCenterDelegate") alloc]; - [notificationCenterDelegate configureForNotifications]; - } - [self performSelector:@selector(configureForNotifications) withObject:self afterDelay:0.3f]; - - return YES; -} - -- (void)configureForNotifications { - if([FIRApp defaultApp] == nil) { - [FIRApp configure]; - } - // For iOS message (sent via FCM) - [FIRMessaging messaging].delegate = self; -} - -+ (void)requestPushPermission:(void (^)(BOOL yesOrNo, NSError* _Nullable error))block withOptions:(NSDictionary*)options { - if ([UNUserNotificationCenter class] == nil) { - return [FCMPluginIOS9Support requestPushPermission:block withOptions:options]; - } - UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; - [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError* _Nullable error) { - if (granted) { - dispatch_async(dispatch_get_main_queue(), ^{ - [[UIApplication sharedApplication] registerForRemoteNotifications]; - }); - block(YES, error); - return; - } - NSLog(@"User Notification permission denied: %@", error.localizedDescription); - block(NO, error); - }]; -} - -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceTokenData { - [FIRMessaging messaging].APNSToken = deviceTokenData; - NSString *deviceToken; - if (@available(iOS 13, *)) { - deviceToken = [self hexadecimalStringFromData:deviceTokenData]; - } else { - deviceToken = [[[[deviceTokenData description] - stringByReplacingOccurrencesOfString:@"<"withString:@""] - stringByReplacingOccurrencesOfString:@">" withString:@""] - stringByReplacingOccurrencesOfString:@" " withString:@""]; - } - apnsToken = deviceToken; - NSLog(@"Device APNS Token: %@", deviceToken); - if (@available(iOS 10, *)) { - return; - } - [FCMPluginIOS9Support application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceTokenData]; -} - -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotifications:(NSError *)error { - NSLog(@"Failed to register for remote notifications: %@", error); - if (@available(iOS 10, *)) { - return; - } - [FCMPluginIOS9Support application:application didFailToRegisterForRemoteNotifications:error]; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-implementations" -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - if (@available(iOS 10, *)) { - return; - } - [FCMPluginIOS9Support application:application didReceiveRemoteNotification:userInfo]; -} -#pragma clang diagnostic pop - -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo -fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { - [[FIRMessaging messaging] appDidReceiveMessage:userInfo]; - - if (@available(iOS 10, *)) { - // Print message ID. - NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); - - // Pring full message. - NSLog(@"%@", userInfo); - - // If the app is in the background, keep it for later, in case it's not tapped. - if(application.applicationState == UIApplicationStateBackground) { - NSError *error; - NSDictionary *userInfoMutable = [userInfo mutableCopy]; - [userInfoMutable setValue:@(NO) forKey:@"wasTapped"]; - NSLog(@"app active"); - lastPush = [NSJSONSerialization dataWithJSONObject:userInfoMutable options:0 error:&error]; - [AppDelegate setInitialPushPayload:lastPush]; - } else if(application.applicationState == UIApplicationStateInactive) { - NSError *error; - NSDictionary *userInfoMutable = [userInfo mutableCopy]; - [userInfoMutable setValue:@(YES) forKey:@"wasTapped"]; - NSLog(@"app opened by user tap"); - lastPush = [NSJSONSerialization dataWithJSONObject:userInfoMutable options:0 error:&error]; - [AppDelegate setInitialPushPayload:lastPush]; - } - - completionHandler(UIBackgroundFetchResultNoData); - return; - } - - [FCMPluginIOS9Support application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; -} -// [END message_handling] - -- (void)messaging:(nonnull FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)deviceToken { - NSLog(@"Device FCM Token: %@", deviceToken); - if(deviceToken == nil) { - fcmToken = nil; - [FCMPlugin.fcmPlugin notifyFCMTokenRefresh:nil]; - return; - } - // Notify about received token. - NSDictionary *dataDict = [NSDictionary dictionaryWithObject:deviceToken forKey:@"token"]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"FCMToken" object:nil userInfo:dataDict]; - fcmToken = deviceToken; - [FCMPlugin.fcmPlugin notifyFCMTokenRefresh:deviceToken]; - [self connectToFcm]; -} - -// [BEGIN connect_to_fcm] -- (void)connectToFcm { - // Won't connect since there is no token - if (!fcmToken) { - return; - } - [[FIRMessaging messaging] subscribeToTopic:@"ios"]; - [[FIRMessaging messaging] subscribeToTopic:@"all"]; -} -// [END connect_to_fcm] - -- (void)applicationDidBecomeActive:(UIApplication *)application { - NSLog(@"app become active"); - [FCMPlugin.fcmPlugin appEnterForeground]; - [self connectToFcm]; -} - -// [BEGIN disconnect_from_fcm] -- (void)applicationDidEnterBackground:(UIApplication *)application { - NSLog(@"app entered background"); - [FCMPlugin.fcmPlugin appEnterBackground]; - NSLog(@"Disconnected from FCM"); -} -// [END disconnect_from_fcm] - -+ (void)setLastPush:(NSData*)push { - lastPush = push; -} - -+ (void)setInitialPushPayload:(NSData*)payload { - if(initialPushPayload == nil) { - initialPushPayload = payload; - } -} - -+ (NSData*)getLastPush { - NSData* returnValue = lastPush; - lastPush = nil; - return returnValue; -} - -+ (NSData*)getInitialPushPayload { - return initialPushPayload; -} - -+ (NSString*)getFCMToken { - return fcmToken; -} - -+ (NSString*)getAPNSToken { - return apnsToken; -} - -+ (void)deleteInstanceId:(void (^)(NSError *error))handler { - [[FIRInstanceID instanceID] deleteIDWithHandler:handler]; -} - -+ (void)hasPushPermission:(void (^)(NSNumber* yesNoOrNil))block { - if ([UNUserNotificationCenter class] == nil) { - [FCMPluginIOS9Support hasPushPermission:block]; - return; - } - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings){ - switch (settings.authorizationStatus) { - case UNAuthorizationStatusAuthorized: { - block([NSNumber numberWithBool:YES]); - } - case UNAuthorizationStatusDenied: { - block([NSNumber numberWithBool:NO]); - } - default: { - block(nil); - } - } - }]; -} - -- (NSString *)hexadecimalStringFromData:(NSData *)data { - NSUInteger dataLength = data.length; - if (dataLength == 0) { - return nil; - } - - const unsigned char *dataBuffer = data.bytes; - NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; - for (int i = 0; i < dataLength; ++i) { - [hexString appendFormat:@"%02x", dataBuffer[i]]; - } - return [hexString copy]; -} - -@end diff --git a/src/ios/Assets/GoogleService-Info.plist b/src/ios/Assets/GoogleService-Info.plist deleted file mode 100644 index 5516ebf30..000000000 --- a/src/ios/Assets/GoogleService-Info.plist +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/ios/FCMNotificationCenterDelegate.h b/src/ios/FCMNotificationCenterDelegate.h deleted file mode 100644 index 027d3c6c4..000000000 --- a/src/ios/FCMNotificationCenterDelegate.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface FCMNotificationCenterDelegate : NSObject {} - -- (void)configureForNotifications; - -@end diff --git a/src/ios/FCMNotificationCenterDelegate.m b/src/ios/FCMNotificationCenterDelegate.m deleted file mode 100644 index 4039fe02c..000000000 --- a/src/ios/FCMNotificationCenterDelegate.m +++ /dev/null @@ -1,117 +0,0 @@ -#import "AppDelegate+FCMPlugin.h" -#import "FCMPlugin.h" -#import "FCMNotificationCenterDelegate.h" -#import -#import - -@import UserNotifications; - -// Implement UNUserNotificationCenterDelegate to receive display notification via APNS for devices -// running iOS 10 and above. -@interface FCMNotificationCenterDelegate () -@end - -@implementation FCMNotificationCenterDelegate - -NSMutableArray*> *subNotificationCenterDelegates; - -- (void) forceNotificationCenterDelegate:(float)timeout { - [self setNotificationCenterDelegate]; - if(timeout < 0) { - // The job should be done. - return; - } - SEL thisMethodSelector = NSSelectorFromString(@"forceNotificationCenterDelegate:"); - if([self respondsToSelector:thisMethodSelector]) { -// NSLog(@"FCMNotificationCenterDelegate found: %@", [UNUserNotificationCenter currentNotificationCenter].delegate); - float remainingTimeout = timeout - 0.1f; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:thisMethodSelector]]; - [invocation setSelector:thisMethodSelector]; - [invocation setTarget:self]; - [invocation setArgument:&(remainingTimeout) atIndex:2]; - [NSTimer scheduledTimerWithTimeInterval:0.1f invocation:invocation repeats:NO]; - return; - } - NSLog(@"forceNotificationCenterDelegate selector not found in FCMNotificationCenterDelegate"); -} - -- (void)configureForNotifications { - subNotificationCenterDelegates = [[NSMutableArray alloc]initWithCapacity:0]; - [self setNotificationCenterDelegate]; - [self forceNotificationCenterDelegate:10]; -} - -- (void) setNotificationCenterDelegate { - if([UNUserNotificationCenter currentNotificationCenter].delegate == self) { - return; - } - if([UNUserNotificationCenter currentNotificationCenter].delegate != nil) { - [subNotificationCenterDelegates addObject:[UNUserNotificationCenter currentNotificationCenter].delegate]; -// NSLog(@"subNotificationCenterDelegates: %@", subNotificationCenterDelegates); - } - [UNUserNotificationCenter currentNotificationCenter].delegate = self; -} - - -// Handle incoming notification messages while app is in the foreground. -- (void)userNotificationCenter:(UNUserNotificationCenter *)center - willPresentNotification:(UNNotification *)notification - withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { - NSLog(@"FCMNotificationCenterDelegate.willPresentNotification!"); - NSData *jsonData = [self extractJSONData:notification withWasTapped:NO]; - [FCMPlugin.fcmPlugin notifyOfMessage:jsonData]; - __block UNNotificationPresentationOptions notificationPresentationOptions = UNNotificationPresentationOptionNone; - void (^subDelegateCompletionHandler)(UNNotificationPresentationOptions) = ^(UNNotificationPresentationOptions possibleNotificationPresentationOptions) { - if(notificationPresentationOptions < possibleNotificationPresentationOptions) { - notificationPresentationOptions |= possibleNotificationPresentationOptions; - } - }; - SEL thisMethodSelector = NSSelectorFromString(@"userNotificationCenter:willPresentNotification:withCompletionHandler:"); - for (NSObject* subNotificationCenterDelegate in subNotificationCenterDelegates) { - if([subNotificationCenterDelegate respondsToSelector:thisMethodSelector]) { - [subNotificationCenterDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:subDelegateCompletionHandler]; - } - } - completionHandler(notificationPresentationOptions); -} - -// Handle notification messages after display notification is tapped by the user. -- (void)userNotificationCenter:(UNUserNotificationCenter *)center -didReceiveNotificationResponse:(UNNotificationResponse *)response - withCompletionHandler:(void (^)(void))completionHandler { - NSLog(@"FCMNotificationCenterDelegate.didReceiveNotificationResponse!"); - NSData *jsonData = [self extractJSONData:response.notification withWasTapped:YES]; - [AppDelegate setInitialPushPayload:jsonData]; - [FCMPlugin.fcmPlugin notifyOfMessage:jsonData]; - void (^noopCompletionHandler)(void) = ^(){}; - SEL thisMethodSelector = NSSelectorFromString(@"userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:"); - for (NSObject* subNotificationCenterDelegate in subNotificationCenterDelegates) { - if([subNotificationCenterDelegate respondsToSelector:thisMethodSelector]) { - [subNotificationCenterDelegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:noopCompletionHandler]; - } - } - completionHandler(); -} - -- (NSData*)extractJSONData:(UNNotification*)notification - withWasTapped:(BOOL)wasTapped { - UNNotificationContent *content = notification.request.content; - NSLog(@"Push notification received: title=\"%@\" subtitle=\"%@\" body=\"%@\" badge=\"%@\"", - content.title, content.subtitle, content.body, content.badge); - NSLog(@"Push data received: %@", content.userInfo); - NSDictionary *notificationData = [content.userInfo mutableCopy]; - if([notificationData objectForKey:@"wasTapped"] == nil) { [notificationData setValue:@(wasTapped) forKey:@"wasTapped"]; } - if([notificationData objectForKey:@"title"] == nil) { [notificationData setValue:content.title forKey:@"title"]; } - if([notificationData objectForKey:@"subtitle"] == nil) { [notificationData setValue:content.subtitle forKey:@"subtitle"]; } - if([notificationData objectForKey:@"body"] == nil) { [notificationData setValue:content.body forKey:@"body"]; } - if([notificationData objectForKey:@"badge"] == nil) { [notificationData setValue:content.badge forKey:@"badge"]; } - NSError *error; - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:notificationData options:0 error:&error]; - if(error != NULL) { - NSLog(@"Error on converting to JSON: %@", notificationData); - return NULL; - } - return jsonData; -} - -@end diff --git a/src/ios/FCMPlugin.h b/src/ios/FCMPlugin.h deleted file mode 100644 index 24e8dc90c..000000000 --- a/src/ios/FCMPlugin.h +++ /dev/null @@ -1,22 +0,0 @@ -#import -#import - -@interface FCMPlugin : CDVPlugin {} - -+ (FCMPlugin *) fcmPlugin; -- (void)notifyFCMTokenRefresh:(NSString*) token; -- (void)ready:(CDVInvokedUrlCommand*)command; -- (void)hasPermission:(CDVInvokedUrlCommand*)command; -- (void)getToken:(CDVInvokedUrlCommand*)command; -- (void)returnTokenOrRetry:(void (^)(NSString* fcmToken))onSuccess; -- (void)getAPNSToken:(CDVInvokedUrlCommand*)command; -- (void)getInitialPushPayload:(CDVInvokedUrlCommand*)command; -- (void)deleteInstanceId:(CDVInvokedUrlCommand*)command; -- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command; -- (void)subscribeToTopic:(CDVInvokedUrlCommand*)command; -- (void)unsubscribeFromTopic:(CDVInvokedUrlCommand*)command; -- (void)notifyOfMessage:(NSData*) payload; -- (void)appEnterBackground; -- (void)appEnterForeground; - -@end diff --git a/src/ios/FCMPlugin.m b/src/ios/FCMPlugin.m deleted file mode 100644 index 0bb0af76e..000000000 --- a/src/ios/FCMPlugin.m +++ /dev/null @@ -1,230 +0,0 @@ -#include -#include -#import "AppDelegate+FCMPlugin.h" -#import -#import -#import -#import "FCMPlugin.h" -#import - -@interface FCMPlugin () {} -@end - -@implementation FCMPlugin - -static BOOL appInForeground = YES; - -static NSString *notificationEventName = @"notification"; -static NSString *tokenRefreshCallback = @"tokenRefresh"; -static NSString *jsEventBridgeCallbackId; -static FCMPlugin *fcmPluginInstance; - -+ (FCMPlugin *)fcmPlugin { - return fcmPluginInstance; -} - -- (void)ready:(CDVInvokedUrlCommand *)command { - NSLog(@"Cordova view ready"); - fcmPluginInstance = self; - [self.commandDelegate runInBackground:^{ - CDVPluginResult* pluginResult = nil; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)hasPermission:(CDVInvokedUrlCommand *)command { - [self.commandDelegate runInBackground:^{ - [AppDelegate hasPushPermission:^(NSNumber* pushPermission){ - __block CDVPluginResult *commandResult; - if (pushPermission == nil) { - NSLog(@"has push permission: unknown"); - commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - } else if ([pushPermission boolValue] == YES) { - NSLog(@"has push permission: true"); - commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES]; - } else if ([pushPermission boolValue] == NO) { - NSLog(@"has push permission: false"); - commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:NO]; - } - [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; - }]; - }]; -} - -- (void)startJsEventBridge:(CDVInvokedUrlCommand *)command { - NSLog(@"start Js Event Bridge"); - jsEventBridgeCallbackId = command.callbackId; -} - -- (void)getToken:(CDVInvokedUrlCommand *)command { - NSLog(@"get Token"); - [self returnTokenOrRetry:^(NSString* fcmToken){ - CDVPluginResult* pluginResult = nil; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:fcmToken]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)returnTokenOrRetry:(void (^)(NSString* fcmToken))onSuccess { - NSString* fcmToken = [AppDelegate getFCMToken]; - if(fcmToken != nil) { - onSuccess(fcmToken); - return; - } - SEL thisMethodSelector = NSSelectorFromString(@"returnTokenOrRetry:"); - NSLog(@"FCMToken unavailable, it'll retry in one second"); - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:thisMethodSelector]]; - [invocation setSelector:thisMethodSelector]; - [invocation setTarget:self]; - [invocation setArgument:&(onSuccess) atIndex:2]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocationion - [NSTimer scheduledTimerWithTimeInterval:1 invocation:invocation repeats:NO]; -} - -- (void)getAPNSToken:(CDVInvokedUrlCommand *)command { - NSLog(@"get APNS Token"); - [self.commandDelegate runInBackground:^{ - CDVPluginResult* pluginResult = nil; - NSString* apnsToken = [AppDelegate getAPNSToken]; - NSLog(@"get APNS Token value: %@", apnsToken); - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:apnsToken]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)clearAllNotifications:(CDVInvokedUrlCommand *)command { - [self.commandDelegate runInBackground:^{ - NSLog(@"clear all notifications"); - [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1]; - [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; - CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)subscribeToTopic:(CDVInvokedUrlCommand *)command { - NSString* topic = [command.arguments objectAtIndex:0]; - NSLog(@"subscribe To Topic %@", topic); - [self.commandDelegate runInBackground:^{ - if(topic != nil)[[FIRMessaging messaging] subscribeToTopic:topic]; - CDVPluginResult* pluginResult = nil; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:topic]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)unsubscribeFromTopic:(CDVInvokedUrlCommand *)command { - NSString* topic = [command.arguments objectAtIndex:0]; - NSLog(@"unsubscribe From Topic %@", topic); - [self.commandDelegate runInBackground:^{ - if(topic != nil)[[FIRMessaging messaging] unsubscribeFromTopic:topic]; - CDVPluginResult* pluginResult = nil; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:topic]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)requestPushPermission:(CDVInvokedUrlCommand *)command { - [self.commandDelegate runInBackground:^{ - NSNumber* ios9SupportTimeout = [command argumentAtIndex:0 withDefault:[NSNumber numberWithFloat:10]]; - NSNumber* ios9SupportInterval = [command argumentAtIndex:1 withDefault:[NSNumber numberWithFloat:0.3]]; - NSLog(@"requestPushPermission { ios9SupportTimeout:%@ ios9SupportInterval:%@ }", ios9SupportTimeout, ios9SupportInterval); - id objects[] = { ios9SupportTimeout, ios9SupportInterval }; - id keys[] = { @"ios9SupportTimeout", @"ios9SupportInterval" }; - NSDictionary* options = [NSDictionary dictionaryWithObjects:objects forKeys:keys count:2]; - [AppDelegate requestPushPermission:^(BOOL pushPermission, NSError* _Nullable error) { - if(error != nil){ - NSLog(@"push permission request error: %@", error); - __block CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error description]]; - [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; - return; - } - NSLog(@"push permission request result: %@", pushPermission ? @"Yes" : @"No"); - __block CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:pushPermission]; - [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; - } withOptions:options]; - }]; -} - -- (void)getInitialPushPayload:(CDVInvokedUrlCommand *)command { - NSLog(@"getInitialPushPayload"); - [self.commandDelegate runInBackground:^{ - NSData* dataPayload = [AppDelegate getInitialPushPayload]; - if (dataPayload == nil) { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - return; - } - NSString *strUTF8 = [[NSString alloc] initWithData:dataPayload encoding:NSUTF8StringEncoding]; - NSData *dataPayloadUTF8 = [strUTF8 dataUsingEncoding:NSUTF8StringEncoding]; - NSError* error = nil; - NSDictionary *payloadDictionary = [NSJSONSerialization JSONObjectWithData:dataPayloadUTF8 options:0 error:&error]; - if (error) { - NSString* errorMessage = [NSString stringWithFormat:@"%@ => '%@'", [error localizedDescription], strUTF8]; - NSLog(@"getInitialPushPayload error: %@", errorMessage); - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:errorMessage]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - return; - } - NSLog(@"getInitialPushPayload value: %@", payloadDictionary); - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:payloadDictionary]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; - }]; -} - -- (void)deleteInstanceId:(CDVInvokedUrlCommand *)command { - [self.commandDelegate runInBackground:^{ - [AppDelegate deleteInstanceId:^(NSError *error) { - __block CDVPluginResult *commandResult; - if(error == nil) { - NSLog(@"InstanceID deleted"); - commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - } else { - NSLog(@"InstanceID deletion error: %@", error); - commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error description]]; - } - [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId]; - }]; - }]; -} - -- (void)notifyOfMessage:(NSData *)payload { - NSLog(@"notifyOfMessage payload: %@", payload); - NSString* JSONString = [[NSString alloc] initWithBytes:[payload bytes] length:[payload length] encoding:NSUTF8StringEncoding]; - [self dispatchJSEvent:notificationEventName withData:JSONString]; -} - -- (void)notifyFCMTokenRefresh:(NSString *)token { - NSLog(@"notifyFCMTokenRefresh token: %@", token); - NSString* jsToken = [NSString stringWithFormat:@"\"%@\"", token]; - [self dispatchJSEvent:tokenRefreshCallback withData:jsToken]; -} - -- (void)dispatchJSEvent:(NSString *)eventName withData:(NSString *)jsData { - if(jsEventBridgeCallbackId == nil) { - NSLog(@"dispatchJSEvent: Unable to send event due to unreachable bridge context: %@ with %@", eventName, jsData); - return; - } - NSLog(@"dispatchJSEvent: %@ with %@", eventName, jsData); - NSString* eventDataTemplate = @"[\"%@\",%@]"; - NSString* eventData = [NSString stringWithFormat:eventDataTemplate, eventName, jsData]; - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:eventData]; - [pluginResult setKeepCallbackAsBool:TRUE]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:jsEventBridgeCallbackId]; -} - -- (void)appEnterBackground { - NSLog(@"Set state background"); - appInForeground = NO; -} - -- (void)appEnterForeground { - NSLog(@"Set state foreground"); - NSData* lastPush = [AppDelegate getLastPush]; - if (lastPush != nil) { - [FCMPlugin.fcmPlugin notifyOfMessage:lastPush]; - } - appInForeground = YES; -} - -@end diff --git a/src/ios/FCMPluginIOS9Support.h b/src/ios/FCMPluginIOS9Support.h deleted file mode 100644 index b768de82e..000000000 --- a/src/ios/FCMPluginIOS9Support.h +++ /dev/null @@ -1,10 +0,0 @@ -@interface FCMPluginIOS9Support : NSObject {} - -+ (void)requestPushPermission:(void (^)(BOOL yesOrNo, NSError* error))block withOptions:(NSDictionary*)options; -+ (void)hasPushPermission:(void (^)(NSNumber* yesNoOrNil))block; -+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo; -+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; -+ (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceTokenData; -+ (void)application:(UIApplication *)application didFailToRegisterForRemoteNotifications:(NSError *)error; - -@end diff --git a/src/ios/FCMPluginIOS9Support.m b/src/ios/FCMPluginIOS9Support.m deleted file mode 100644 index 038b009f2..000000000 --- a/src/ios/FCMPluginIOS9Support.m +++ /dev/null @@ -1,156 +0,0 @@ -#import -#import -#import "FCMPlugin.h" -#import "FCMPluginIOS9Support.h" -#import "AppDelegate+FCMPlugin.h" - -@interface FCMPluginIOS9Support () {} -@end - -@implementation FCMPluginIOS9Support - -NSString *const hasRequestedPushPermissionPersistenceKey = @"FCMPlugin.iOS9.hasRequestedPushPermission"; -static void (^requestPushPermissionCallback)(BOOL yesOrNo, NSError* _Nullable error); - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -+ (void)requestPushPermission:(void (^)(BOOL yesOrNo, NSError* _Nullable error))block withOptions:(NSDictionary*)options { - requestPushPermissionCallback = block; - UIUserNotificationType allNotificationTypes = - (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge); - UIUserNotificationSettings *settings = - [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil]; - [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; - NSNumber* ios9SupportTimeout = options[@"ios9SupportTimeout"]; - float timeout = [ios9SupportTimeout floatValue]; - NSNumber* ios9SupportInterval = options[@"ios9SupportInterval"]; - float interval = [ios9SupportInterval floatValue]; - dispatch_async(dispatch_get_main_queue(), ^{ - [[UIApplication sharedApplication] registerForRemoteNotifications]; - [self waitForUserDecision:timeout withInterval:interval]; - }); -} -#pragma clang diagnostic pop - -+ (void)callbackRequestPushPermission:(BOOL)yesOrNo { - [self callbackRequestPushPermission:yesOrNo withError:nil]; -} - -+ (void)callbackRequestPushPermission:(BOOL)yesOrNo withError:(NSError* _Nullable)error { - [self setHasRequestedPushPermission:YES]; - if(requestPushPermissionCallback != nil) { - requestPushPermissionCallback(yesOrNo, error); - requestPushPermissionCallback = nil; - } -} - -+ (void)waitForUserDecision:(float)timeout withInterval:(float)interval { - [self hasPushPermission:^(NSNumber* pushPermission){ - if(pushPermission != nil) { - // User has chosen. - [self callbackRequestPushPermission:[pushPermission boolValue]]; - return; - } - if(timeout < 0) { - // We have to speculate that the request was not accepted - [self callbackRequestPushPermission:NO]; - return; - } - SEL thisMethodSelector = NSSelectorFromString(@"waitForUserDecision:withInterval:"); - if(![self respondsToSelector:thisMethodSelector]) { - NSLog(@"waitForUserDecision:withInterval: selector not found in FCMPluginIOS9Support"); - return; - } - float remainingTimeout = timeout - interval; - float givenInterval = interval; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:thisMethodSelector]]; - [invocation setSelector:thisMethodSelector]; - [invocation setTarget:self]; - [invocation setArgument:&(remainingTimeout) atIndex:2]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocationion - [invocation setArgument:&(givenInterval) atIndex:3]; - [NSTimer scheduledTimerWithTimeInterval:interval invocation:invocation repeats:NO]; - }]; -} - -+ (void)setHasRequestedPushPermission:(BOOL)pushPermission { - [[NSUserDefaults standardUserDefaults] - setObject:[NSNumber numberWithBool:pushPermission] forKey:hasRequestedPushPermissionPersistenceKey]; - [[NSUserDefaults standardUserDefaults] synchronize]; -} - -+ (BOOL)getHasRequestedPushPermission { - if ([[NSUserDefaults standardUserDefaults] objectForKey:hasRequestedPushPermissionPersistenceKey]) { - bool hasRequestedPushPermission = [[[NSUserDefaults standardUserDefaults] - objectForKey:hasRequestedPushPermissionPersistenceKey] boolValue]; - return hasRequestedPushPermission; - } - return NO; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -+ (void)hasPushPermission:(void (^)(NSNumber* yesNoOrNil))block { - NSString* apnsToken = [AppDelegate getAPNSToken]; - if(apnsToken != nil) { - block([NSNumber numberWithBool:YES]); - return; - } - if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) { - block([NSNumber numberWithBool:YES]); - return; - } - UIUserNotificationSettings *notificationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; - BOOL itDoesHaveNotificationSettings = ((int) notificationSettings.types) != 0; - if(itDoesHaveNotificationSettings) { - block([NSNumber numberWithBool:YES]); - } - BOOL alreadyRequested = [self getHasRequestedPushPermission]; - block(alreadyRequested ? [NSNumber numberWithBool:NO] : nil); -} -#pragma clang diagnostic pop - -+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); - NSError *error; - NSDictionary *userInfoMutable = [userInfo mutableCopy]; - if (application.applicationState != UIApplicationStateActive) { - NSLog(@"New method with push callback: %@", userInfo); - [userInfoMutable setValue:@(YES) forKey:@"wasTapped"]; - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfoMutable options:0 error:&error]; - NSLog(@"APP WAS CLOSED DURING PUSH RECEPTION Saved data: %@", jsonData); - [AppDelegate setInitialPushPayload:jsonData]; - [AppDelegate setLastPush:jsonData]; - } -} - -+ (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceTokenData { - [self callbackRequestPushPermission:YES]; -} - -+ (void)application:(UIApplication *)application didFailToRegisterForRemoteNotifications:(NSError *)error { - [self callbackRequestPushPermission:NO withError:error]; -} - -+ (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { - NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); - NSLog(@"%@", userInfo); - NSError *error; - NSDictionary *userInfoMutable = [userInfo mutableCopy]; - - // Has user tapped the notificaiton? - // UIApplicationStateActive - app is currently active - // UIApplicationStateInactive - app is transitioning from background to - // foreground (user taps notification) - if (application.applicationState == UIApplicationStateActive - || application.applicationState == UIApplicationStateInactive) { - [userInfoMutable setValue:@(NO) forKey:@"wasTapped"]; - NSLog(@"app active"); - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfoMutable - options:0 - error:&error]; - [FCMPlugin.fcmPlugin notifyOfMessage:jsonData]; - } - completionHandler(UIBackgroundFetchResultNoData); -} - -@end