diff --git a/.gitignore b/.gitignore index 763301f..b85f96f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ dist/ -node_modules/ \ No newline at end of file +node_modules/ + + +Pods \ No newline at end of file diff --git a/CapacitorFCM.podspec b/CapacitorFCM.podspec index 7906515..f55fda9 100644 --- a/CapacitorFCM.podspec +++ b/CapacitorFCM.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| - s.name = 'CapacitorFCM' + s.name = 'CapacitorFcm' s.version = '0.0.1' s.summary = 'bring firebase cloud messaging feature to capacitor' s.license = 'MIT' @@ -10,6 +10,7 @@ s.source_files = 'ios/Plugin/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' s.ios.deployment_target = '11.0' s.dependency 'Capacitor' + s.dependency 'Firebase' s.dependency 'FirebaseMessaging' s.dependency 'FirebaseCore' s.dependency 'FirebaseAnalytics' diff --git a/README.md b/README.md index 0701b85..93accd3 100644 --- a/README.md +++ b/README.md @@ -1,271 +1,79 @@ # capacitor-fcm -Capacitor plugin to enable Firebase Cloud Messaging - -## Notice - -> This plugin is currently under active development and has not yet been published. - -## iOS - -- [x] subscribe to topic -- [x] unsubscribe from topic -- [ ] get token - -## Android - -- [ ] subscribe to topic -- [ ] unsubscribe from topic -- [ ] get token - -## Steps - -**Important** - -For now I'm using a custom capacitor build (locally), so you have to change the path at [podfile](https://github.com/stewwan/capacitor-fcm/blob/master/ios/Plugin/Podfile). - -- git clone this repo -- npm install -- npm run build -- npm link -- cd `ios/Plugin` -- pod install -- go back to your capacitor powered app and `npm link capacitor-fcm` -- cd to `ios/App/Podfile` and add - ``` - pod 'Firebase/Core' - pod 'Firebase/Messaging' - pod 'CapacitorFCM', :path => '/path_to_this_repo/capacitor-fcm' - ``` -- pod install - -## Important step (iOS) - -open your client `AppDelegate.swift` and make the necessary changes to reflect the following - -```swift -import UIKit -import UserNotifications -import Capacitor -import Firebase - -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - let gcmMessageIDKey = "gcm.message_id" - - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. - FirebaseApp.configure() - // [START set_messaging_delegate] - Messaging.messaging().delegate = self - // [END set_messaging_delegate] - - - // Register for remote notifications. This shows a permission dialog on first run, to - // show the dialog at a more appropriate time move this registration accordingly. - // [START register_for_notifications] - if #available(iOS 10.0, *) { - // For iOS 10 display notification (sent via APNS) - UNUserNotificationCenter.current().delegate = self - - let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] - UNUserNotificationCenter.current().requestAuthorization( - options: authOptions, - completionHandler: {_, _ in }) - } else { - let settings: UIUserNotificationSettings = - UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) - application.registerUserNotificationSettings(settings) - } - - application.registerForRemoteNotifications() - - // [END register_for_notifications] - - // - // lines below is a workaround for webview input's issue - NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) - - return true - } - - - - // - // webview workaround - @objc func keyboardWillHide(notification: NSNotification) { - if #available(iOS 12.0, *) { - let vc = self.window?.rootViewController as! CAPBridgeViewController - for v in vc.bridgedWebView!.subviews { - if v is UIScrollView { - let scrollView = v as! UIScrollView - scrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: false) - } - } - } - } - - - func applicationWillResignActive(_ application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(_ application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(_ application: UIApplication) { - // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(_ application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(_ application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { - // Called when the app was launched with a url. Feel free to add additional processing here, - // but if you want the App API to support tracking app url opens, make sure to keep this call - return CAPBridge.handleOpenUrl(url, options) - } - - func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { - // Called when the app was launched with an activity, including Universal Links. - // Feel free to add additional processing here, but if you want the App API to support - // tracking app url opens, make sure to keep this call - return CAPBridge.handleContinueActivity(userActivity, restorationHandler) - } - - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - super.touchesBegan(touches, with: event) - - let statusBarRect = UIApplication.shared.statusBarFrame - guard let touchPoint = event?.allTouches?.first?.location(in: self.window) else { return } - - if statusBarRect.contains(touchPoint) { - NotificationCenter.default.post(CAPBridge.statusBarTappedNotification) - } - } - - // [START receive_message] - func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { - // If you are receiving a notification message while your app is in the background, - // this callback will not be fired till the user taps on the notification launching the application. - // TODO: Handle data of notification - // With swizzling disabled you must let Messaging know about the message, for Analytics - // Messaging.messaging().appDidReceiveMessage(userInfo) - // Print message ID. - if let messageID = userInfo[gcmMessageIDKey] { - print("Message ID: \(messageID)") - } - - // Print full message. - print(userInfo) - } - - func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], - fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { - // If you are receiving a notification message while your app is in the background, - // this callback will not be fired till the user taps on the notification launching the application. - // TODO: Handle data of notification - // With swizzling disabled you must let Messaging know about the message, for Analytics - // Messaging.messaging().appDidReceiveMessage(userInfo) - // Print message ID. - if let messageID = userInfo[gcmMessageIDKey] { - print("Message ID: \(messageID)") - } - - // Print full message. - print(userInfo) - - completionHandler(UIBackgroundFetchResult.newData) - } - // [END receive_message] - func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { - print("Unable to register for remote notifications: \(error.localizedDescription)") - } - - // This function is added here only for debugging purposes, and can be removed if swizzling is enabled. - // If swizzling is disabled then this function must be implemented so that the APNs token can be paired to - // the FCM registration token. - func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { - print("APNs token retrieved: \(deviceToken)") +Capacitor plugin to enable features from Firebase Cloud Messaging + +## API + +- subscribeTo +- unsubscribeFrom +- getToken + +## Usage + +```js +import { FCM } from "capacitor-fcm"; +const fcm = new FCM(); + +import { Plugins } from "@capacitor/core"; +const { PushNotifications } = Plugins; + +// +// Subscribe to a specific topic +PushNotifications.register() + .then(_ => { + fcm + .subscribeTo({ topic: "test" }) + .then(r => alert(`subscribed to topic`)) + .catch(err => console.log(err)); + }) + .catch(err => alert(JSON.stringify(err))); + +// +// Unsubscribe from a specific topic +fcm + .unsubscribeFrom({ topic: "test" }) + .then(r => alert(`unsubscribed from topic`)) + .catch(err => console.log(err)); +} - // With swizzling disabled you must set the APNs token here. - // Messaging.messaging().apnsToken = deviceToken - } +// +// get remote token +fcm + .getToken() + .then(r => alert(`Token ${r.token}`)) + .catch(err => console.log(err)); } +``` -// [START ios_10_message_handling] -@available(iOS 10, *) -extension AppDelegate : UNUserNotificationCenterDelegate { +## iOS setup - // Receive displayed notifications for iOS 10 devices. - func userNotificationCenter(_ center: UNUserNotificationCenter, - willPresent notification: UNNotification, - withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { - let userInfo = notification.request.content.userInfo +- `ionic start my-cap-app --capacitor` +- `cd my-cap-app` +- `npm install —-save capacitor-fcm` +- `mkdir www && touch www/index.html` +- `npx cap add ios` +- npx cap open ios +- sign your app at xcode (general tab) +- enable remote notification capabilities +- add `GoogleService-Info.plist` to your app in xcode - // With swizzling disabled you must let Messaging know about the message, for Analytics - // Messaging.messaging().appDidReceiveMessage(userInfo) - // Print message ID. - if let messageID = userInfo[gcmMessageIDKey] { - print("Message ID: \(messageID)") - } +Then you should be set to go. Run `ionic cap run ios --livereload` to start the server and play it through xcode - // Print full message. - print(userInfo) +> Important Notice: every time you change a native code you may need to clean the cache (Product > Clean build folder) and then run the app again. - // Change this to your preferred presentation option - completionHandler([]) - } +## Android setup - func userNotificationCenter(_ center: UNUserNotificationCenter, - didReceive response: UNNotificationResponse, - withCompletionHandler completionHandler: @escaping () -> Void) { - let userInfo = response.notification.request.content.userInfo - // Print message ID. - if let messageID = userInfo[gcmMessageIDKey] { - print("Message ID: \(messageID)") - } +(soon) - // Print full message. - print(userInfo) +## Add Google config files - completionHandler() - } -} -// [END ios_10_message_handling] +Navigate to the project settings page for your application on Firebase. -extension AppDelegate : MessagingDelegate { - // [START refresh_token] - func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) { - print("Firebase registration token: \(fcmToken)") +Android: Download the google-services.json file and copy it to the android/app/ directory of your capacitor project. You will also need to add the Firebase SDK to your gradle files. More info can be found here: https://firebase.google.com/docs/android/setup#manually_add_firebase - let dataDict:[String: String] = ["token": fcmToken] - NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict) - // TODO: If necessary send token to application server. - // Note: This callback is fired at each app startup and whenever a new token is generated. - } - // [END refresh_token] - // [START ios_10_data_message] - // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground. - // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true. - func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) { - print("Received data message: \(remoteMessage.appData)") - } - // [END ios_10_data_message] -} -``` +iOS: Download the GoogleService-Info.plist file. In Xcode right-click on the yellow folder named, "App" and select the 'Add files to "App"'. tip: if you drag and drop your file to this location, Xcode may not be able to find it. + +That's all folks. ## Don't forget @@ -275,6 +83,8 @@ extension AppDelegate : MessagingDelegate { After all of these steps you should be set to go. Try to run your client using `ionic cap run ios`. +That's all folks. + Follow me [@Twitter](https://twitter.com/StewanSilva) ## License diff --git a/android/capacitor-fcm/src/main/AndroidManifest.xml b/android/capacitor-fcm/src/main/AndroidManifest.xml index 06d8b23..5fcbcb0 100644 --- a/android/capacitor-fcm/src/main/AndroidManifest.xml +++ b/android/capacitor-fcm/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ + package="io.stewan.capacitor-fcm"> diff --git a/ios/Plugin/Plugin.xcodeproj/project.pbxproj b/ios/Plugin/Plugin.xcodeproj/project.pbxproj index 175fabc..413d55f 100644 --- a/ios/Plugin/Plugin.xcodeproj/project.pbxproj +++ b/ios/Plugin/Plugin.xcodeproj/project.pbxproj @@ -291,6 +291,7 @@ "${SRCROOT}/Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests-frameworks.sh", "${BUILT_PRODUCTS_DIR}/Capacitor/Capacitor.framework", "${BUILT_PRODUCTS_DIR}/CapacitorCordova/Cordova.framework", + "${BUILT_PRODUCTS_DIR}/GCDWebServer/GCDWebServer.framework", "${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework", "${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework", "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework", @@ -299,6 +300,7 @@ outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Capacitor.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cordova.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GCDWebServer.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework", diff --git a/ios/Plugin/Plugin.xcworkspace/xcuserdata/stewan.xcuserdatad/UserInterfaceState.xcuserstate b/ios/Plugin/Plugin.xcworkspace/xcuserdata/stewan.xcuserdatad/UserInterfaceState.xcuserstate index a1f85d0..bb7a526 100644 Binary files a/ios/Plugin/Plugin.xcworkspace/xcuserdata/stewan.xcuserdatad/UserInterfaceState.xcuserstate and b/ios/Plugin/Plugin.xcworkspace/xcuserdata/stewan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios/Plugin/Plugin/Plugin.m b/ios/Plugin/Plugin/Plugin.m index 939c7cd..b8aff5b 100644 --- a/ios/Plugin/Plugin/Plugin.m +++ b/ios/Plugin/Plugin/Plugin.m @@ -6,4 +6,5 @@ CAP_PLUGIN(FCM, "FCMPlugin", CAP_PLUGIN_METHOD(subscribeTo, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(unsubscribeFrom, CAPPluginReturnPromise); + CAP_PLUGIN_METHOD(getToken, CAPPluginReturnPromise); ) diff --git a/ios/Plugin/Plugin/Plugin.swift b/ios/Plugin/Plugin/Plugin.swift index 86aa408..5199851 100644 --- a/ios/Plugin/Plugin/Plugin.swift +++ b/ios/Plugin/Plugin/Plugin.swift @@ -1,21 +1,26 @@ import Foundation import Capacitor +import UserNotifications + import FirebaseMessaging import FirebaseCore import FirebaseAnalytics import FirebaseInstanceID - /** * Please read the Capacitor iOS Plugin Development Guide * here: https://capacitor.ionicframework.com/docs/plugins/ios */ @objc(FCM) -public class FCM: CAPPlugin { +public class FCM: CAPPlugin, MessagingDelegate { + + public override func load() { + FirebaseApp.configure() + Messaging.messaging().delegate = self + } @objc func subscribeTo(_ call: CAPPluginCall) { - // [START subscribe_topic] let topicName = call.getString("topic") ?? "" Messaging.messaging().subscribe(toTopic: topicName) { error in // print("Subscribed to weather topic") @@ -28,16 +33,12 @@ public class FCM: CAPPlugin { ]) } } - // [END subscribe_topic] } @objc func unsubscribeFrom(_ call: CAPPluginCall) { - // [START subscribe_topic] let topicName = call.getString("topic") ?? "" Messaging.messaging().unsubscribe(fromTopic: topicName) { error in - // print("UnSubscribed from weather topic") if ((error) != nil) { - print("ERROR while trying to unsubscribe from topic \(topicName)") call.error("Can't unsubscribe from topic \(topicName)") }else{ call.success([ @@ -45,31 +46,17 @@ public class FCM: CAPPlugin { ]) } } - // [END subscribe_topic] } - - // @todo @objc func getToken(_ call: CAPPluginCall) { - // // [START log_fcm_reg_token] - // let token = Messaging.messaging().fcmToken - // print("FCM token: \(token ?? "")") - // // [END log_fcm_reg_token] - // - // - // call.success([ - // "token": token as Any - // ]) - // - // // [START log_iid_reg_token] - // InstanceID.instanceID().instanceID { (result, error) in - // if let error = error { - // print("Error fetching remote instance ID: \(error)") - // } else if let result = result { - // print("Remote instance ID token: \(result.token)") - // - // } - // } - // // [END log_iid_reg_token] + InstanceID.instanceID().instanceID { (result, error) in + if let error = error { + call.error("Error", error) + } else if let result = result { + call.success([ + "token": result.token + ]) + } + } } } diff --git a/ios/Plugin/Podfile b/ios/Plugin/Podfile index 8224844..3b120a1 100644 --- a/ios/Plugin/Podfile +++ b/ios/Plugin/Podfile @@ -6,20 +6,15 @@ target 'Plugin' do use_frameworks! # Pods for IonicRunner - - #pod 'Firebase' pod 'Firebase/Core' pod 'Firebase/Messaging' - pod 'Capacitor', :path => '/Users/stewan/dev/capacitor' - # pod 'Capacitor' ## uncomment to use capacitor's in production version + pod 'Capacitor' end target 'PluginTests' do use_frameworks! - #pod 'Firebase' pod 'Firebase/Core' pod 'Firebase/Messaging' - pod 'Capacitor', :path => '/Users/stewan/dev/capacitor' - # pod 'Capacitor' ## uncomment to use capacitor's in production version + pod 'Capacitor' end diff --git a/ios/Plugin/Podfile.lock b/ios/Plugin/Podfile.lock index bd9e7a2..fb1d2d0 100644 --- a/ios/Plugin/Podfile.lock +++ b/ios/Plugin/Podfile.lock @@ -1,76 +1,83 @@ PODS: - - Capacitor (1.0.0-beta.13): - - CapacitorCordova (= 1.0.0-beta.13) - - CapacitorCordova (1.0.0-beta.13) - - Firebase/Core (5.15.0): + - Capacitor (0.0.113): + - CapacitorCordova (= 0.0.113) + - GCDWebServer (~> 3.0) + - CapacitorCordova (0.0.113) + - Firebase/Core (5.19.0): - Firebase/CoreOnly - - FirebaseAnalytics (= 5.4.0) - - Firebase/CoreOnly (5.15.0): - - FirebaseCore (= 5.1.10) - - Firebase/Messaging (5.15.0): + - FirebaseAnalytics (= 5.8.0) + - Firebase/CoreOnly (5.19.0): + - FirebaseCore (= 5.4.0) + - Firebase/Messaging (5.19.0): - Firebase/CoreOnly - - FirebaseMessaging (= 3.2.2) - - FirebaseAnalytics (5.4.0): - - FirebaseCore (~> 5.1) - - FirebaseInstanceID (~> 3.3) - - GoogleAppMeasurement (= 5.4.0) + - FirebaseMessaging (= 3.4.0) + - FirebaseAnalytics (5.8.0): + - FirebaseCore (~> 5.4) + - FirebaseInstanceID (~> 3.8) + - GoogleAppMeasurement (= 5.8.0) - GoogleUtilities/AppDelegateSwizzler (~> 5.2) - GoogleUtilities/MethodSwizzler (~> 5.2) - GoogleUtilities/Network (~> 5.2) - "GoogleUtilities/NSData+zlib (~> 5.2)" - nanopb (~> 0.3) - - FirebaseAnalyticsInterop (1.1.0) - - FirebaseCore (5.1.10): + - FirebaseAnalyticsInterop (1.2.0) + - FirebaseCore (5.4.0): + - GoogleUtilities/Environment (~> 5.2) - GoogleUtilities/Logger (~> 5.2) - - FirebaseInstanceID (3.3.0): - - FirebaseCore (~> 5.1) + - FirebaseInstanceID (3.8.0): + - FirebaseCore (~> 5.2) + - GoogleUtilities/Environment (~> 5.2) + - GoogleUtilities/UserDefaults (~> 5.2) + - FirebaseMessaging (3.4.0): + - FirebaseAnalyticsInterop (~> 1.1) + - FirebaseCore (~> 5.2) + - FirebaseInstanceID (~> 3.6) - GoogleUtilities/Environment (~> 5.3) + - GoogleUtilities/Reachability (~> 5.3) - GoogleUtilities/UserDefaults (~> 5.3) - - FirebaseMessaging (3.2.2): - - FirebaseAnalyticsInterop (~> 1.1) - - FirebaseCore (~> 5.1) - - FirebaseInstanceID (~> 3.0) - - GoogleUtilities/Environment (~> 5.2) - - GoogleUtilities/Reachability (~> 5.2) - Protobuf (~> 3.1) - - GoogleAppMeasurement (5.4.0): + - GCDWebServer (3.5.2): + - GCDWebServer/Core (= 3.5.2) + - GCDWebServer/Core (3.5.2) + - GoogleAppMeasurement (5.8.0): - GoogleUtilities/AppDelegateSwizzler (~> 5.2) - GoogleUtilities/MethodSwizzler (~> 5.2) - GoogleUtilities/Network (~> 5.2) - "GoogleUtilities/NSData+zlib (~> 5.2)" - nanopb (~> 0.3) - - GoogleUtilities/AppDelegateSwizzler (5.3.7): + - GoogleUtilities/AppDelegateSwizzler (5.5.0): - GoogleUtilities/Environment - GoogleUtilities/Logger - GoogleUtilities/Network - - GoogleUtilities/Environment (5.3.7) - - GoogleUtilities/Logger (5.3.7): + - GoogleUtilities/Environment (5.5.0) + - GoogleUtilities/Logger (5.5.0): - GoogleUtilities/Environment - - GoogleUtilities/MethodSwizzler (5.3.7): + - GoogleUtilities/MethodSwizzler (5.5.0): - GoogleUtilities/Logger - - GoogleUtilities/Network (5.3.7): + - GoogleUtilities/Network (5.5.0): - GoogleUtilities/Logger - "GoogleUtilities/NSData+zlib" - GoogleUtilities/Reachability - - "GoogleUtilities/NSData+zlib (5.3.7)" - - GoogleUtilities/Reachability (5.3.7): + - "GoogleUtilities/NSData+zlib (5.5.0)" + - GoogleUtilities/Reachability (5.5.0): - GoogleUtilities/Logger - - GoogleUtilities/UserDefaults (5.3.7): + - GoogleUtilities/UserDefaults (5.5.0): - GoogleUtilities/Logger - nanopb (0.3.901): - nanopb/decode (= 0.3.901) - nanopb/encode (= 0.3.901) - nanopb/decode (0.3.901) - nanopb/encode (0.3.901) - - Protobuf (3.6.1) + - Protobuf (3.7.0) DEPENDENCIES: - - Capacitor (from `/Users/stewan/dev/capacitor`) + - Capacitor - Firebase/Core - Firebase/Messaging SPEC REPOS: https://github.com/cocoapods/specs.git: + - Capacitor - CapacitorCordova - Firebase - FirebaseAnalytics @@ -78,29 +85,27 @@ SPEC REPOS: - FirebaseCore - FirebaseInstanceID - FirebaseMessaging + - GCDWebServer - GoogleAppMeasurement - GoogleUtilities - nanopb - Protobuf -EXTERNAL SOURCES: - Capacitor: - :path: "/Users/stewan/dev/capacitor" - SPEC CHECKSUMS: - Capacitor: 7768a5ccfb0c8514fd7a03f4c673e95073cd5480 - CapacitorCordova: 787c1b04319cbcba4b60c24902b1d9068eacf276 - Firebase: 8bb9268bff82374f2cbaaabb143e725743c316ae - FirebaseAnalytics: c06f9d70577d79074214700a71fd5d39de5550fb - FirebaseAnalyticsInterop: e5f21be9af6548372e2f0815834ff909bff395a2 - FirebaseCore: 35747502d9e8c6ee217385ad04446c7c2aaf9c5c - FirebaseInstanceID: e2fa4cb35ef5558c200f7f0ad8a53e212215f93e - FirebaseMessaging: b412996f6a09337d232bb3a6676ce4d1f353d024 - GoogleAppMeasurement: 98b71f5e04142793729a5ef23e5b96651ff4b70f - GoogleUtilities: 111a012f4c3a29c9e7c954c082fafd6ee3c999c0 + Capacitor: b37060b0b2685257bedbc69e49a54a74ef30fb9a + CapacitorCordova: a923a32bc7ad5f1f3d69664ca86ff69580343ed3 + Firebase: c60d49e9c2630875a96207d15e2affb8364996d1 + FirebaseAnalytics: fd72a26bf8dac84cefba2f0864366f718555a5b0 + FirebaseAnalyticsInterop: efbe45c8385ec626e29f9525e5ebd38520dfb6c1 + FirebaseCore: 22a79a961c3951ef2f77b67bfbc99e454247b319 + FirebaseInstanceID: cf488df2f4b79782f0e430b04a0e17c0aa7979b2 + FirebaseMessaging: 2d53d08d752fbe63ce0820428d70be5ab87c11fb + GCDWebServer: ead88cd14596dd4eae4f5830b8877c87c8728990 + GoogleAppMeasurement: 1624046ab1bcc5e170061a56ef5679000b079c8e + GoogleUtilities: 6481e6318c5fcabaaa8513ef8120f329055d7c10 nanopb: 2901f78ea1b7b4015c860c2fdd1ea2fee1a18d48 - Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5 + Protobuf: 7a877b7f3e5964e3fce995e2eb323dbc6831bb5a -PODFILE CHECKSUM: a767bf1a2b2ce941dae84af025731ef76301b645 +PODFILE CHECKSUM: 0c931cbd006199b09701f70eee23aee441dedaf5 COCOAPODS: 1.5.3 diff --git a/package.json b/package.json index 785573d..9aed390 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,18 @@ { "name": "capacitor-fcm", "version": "0.0.1", - "description": "bring firebase cloud messaging feature to capacitor", + "description": "Brings Firebase Cloud Messaging features to Capacitor", "main": "dist/esm/index.js", "types": "dist/esm/index.d.ts", "scripts": { "build": "npm run clean && tsc", "clean": "rm -rf ./dist", "watch": "tsc --watch", - "prepublishOnly": "npm run build" + "prepublishOnly": "npm run build", + "release:custom": "standard-version release --release-as x.x.x", + "release:patch": "standard-version release --release-as patch", + "release:minor": "standard-version release --release-as minor", + "release:major": "standard-version release --release-as major" }, "author": "Stewan Silva", "license": "MIT", @@ -27,7 +31,9 @@ "keywords": [ "capacitor", "plugin", - "native" + "native", + "fcm", + "firebase cloud messaging" ], "capacitor": { "ios": { diff --git a/src/definitions.ts b/src/definitions.ts index c021671..5fbf62d 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -5,6 +5,7 @@ declare global { } export interface IFCMPlugin { - subscribeTo(options: { topic: string }): Promise; - unsubscribeFrom(options: { topic: string }): Promise; + subscribeTo(options: { topic: string }): Promise<{ message: string }>; + unsubscribeFrom(options: { topic: string }): Promise<{ message: string }>; + getToken(): Promise<{ token: string }>; } diff --git a/src/plugin.ts b/src/plugin.ts index da81212..1300149 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -4,10 +4,13 @@ import { IFCMPlugin } from "./definitions"; const { FCMPlugin } = Plugins; export class FCM implements IFCMPlugin { - subscribeTo(options: { topic: string }): Promise { + subscribeTo(options: { topic: string }) { return FCMPlugin.subscribeTo({ topic: options.topic }); } - unsubscribeFrom(options: { topic: string }): Promise { + unsubscribeFrom(options: { topic: string }) { return FCMPlugin.unsubscribeFrom({ topic: options.topic }); } + getToken() { + return FCMPlugin.getToken(); + } }