diff --git a/apps/demo-angular/nativescript.config.ts b/apps/demo-angular/nativescript.config.ts index 395e2759..dc6778f8 100644 --- a/apps/demo-angular/nativescript.config.ts +++ b/apps/demo-angular/nativescript.config.ts @@ -1,7 +1,8 @@ import { NativeScriptConfig } from '@nativescript/core'; export default { - id: 'org.nativescript.plugindemoangular', + // id: 'org.nativescript.plugindemoangular', + id: 'io.github.triniwiz.nativescript.firebasedemo', appResourcesPath: '../../tools/assets/App_Resources', android: { v8Flags: '--expose_gc', diff --git a/apps/demo-angular/src/app.component.ts b/apps/demo-angular/src/app.component.ts index e37a75f9..2813bee6 100644 --- a/apps/demo-angular/src/app.component.ts +++ b/apps/demo-angular/src/app.component.ts @@ -1,9 +1,11 @@ import { Component } from '@angular/core'; - +import { AppService } from './app.service'; @Component({ selector: 'demo-app', template: ` `, }) -export class AppComponent {} +export class AppComponent { + constructor(appService: AppService){} +} diff --git a/apps/demo-angular/src/app.module.ts b/apps/demo-angular/src/app.module.ts index c869e4d1..6efd6983 100644 --- a/apps/demo-angular/src/app.module.ts +++ b/apps/demo-angular/src/app.module.ts @@ -4,11 +4,13 @@ import { NativeScriptModule } from '@nativescript/angular'; import { AppComponent } from './app.component'; import { AppRoutingModule } from './app-routing.module'; import { HomeComponent } from './home.component'; +import { AppService } from './app.service'; @NgModule({ schemas: [NO_ERRORS_SCHEMA], declarations: [AppComponent, HomeComponent], bootstrap: [AppComponent], imports: [NativeScriptModule, AppRoutingModule], + providers: [AppService] }) export class AppModule {} diff --git a/apps/demo-angular/src/app.service.ts b/apps/demo-angular/src/app.service.ts new file mode 100644 index 00000000..9ac8b473 --- /dev/null +++ b/apps/demo-angular/src/app.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { firebase } from '@nativescript/firebase-core'; +import '@nativescript/firebase-messaging'; + +@Injectable() +export class AppService { + constructor() { + const messaging = firebase().messaging(); + messaging.onToken((token) => { + console.log('Firebase onToken', token); + }); + messaging.onMessage((message) => { + console.log('Firebase onMessage', message); + }); + + messaging.onNotificationTap((message) => { + console.log('Firebase onNotificationTap', message); + }); + + } +} diff --git a/apps/demo-angular/src/main.ts b/apps/demo-angular/src/main.ts index d863ba5b..43416fb8 100644 --- a/apps/demo-angular/src/main.ts +++ b/apps/demo-angular/src/main.ts @@ -1,6 +1,32 @@ import { runNativeScriptAngularApp, platformNativeScript } from '@nativescript/angular'; import { AppModule } from './app.module'; +import { firebase } from '@nativescript/firebase-core'; +import { Application } from '@nativescript/core'; + +Application.on('launch', (args) => { + console.log('launch'); +}); + +firebase() + .initializeApp() + .then((done) => { + console.log('initializeApp'); + }); + +const messaging = firebase().messaging(); + +messaging + .requestPermission() + .then(() => { + console.log('requestPermission', 'done'); + messaging.registerDeviceForRemoteMessages().catch((e) => { + console.error('registerDeviceForRemoteMessages', e); + }); + }) + .catch((e) => { + console.error('requestPermission', e); + }); runNativeScriptAngularApp({ - appModuleBootstrap: () => platformNativeScript().bootstrapModule(AppModule), -}); \ No newline at end of file + appModuleBootstrap: () => platformNativeScript().bootstrapModule(AppModule), +}); diff --git a/packages/firebase-admob/package.json b/packages/firebase-admob/package.json index 72bf81dc..25ddabc9 100644 --- a/packages/firebase-admob/package.json +++ b/packages/firebase-admob/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-admob", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Admob", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-analytics/package.json b/packages/firebase-analytics/package.json index 8761be18..43157b9c 100644 --- a/packages/firebase-analytics/package.json +++ b/packages/firebase-analytics/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-analytics", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Analytics", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-app-check/package.json b/packages/firebase-app-check/package.json index 8d87d4f3..7421b3e4 100644 --- a/packages/firebase-app-check/package.json +++ b/packages/firebase-app-check/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-app-check", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - App Check", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-auth/package.json b/packages/firebase-auth/package.json index 863b3946..d6e9aeac 100644 --- a/packages/firebase-auth/package.json +++ b/packages/firebase-auth/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-auth", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Auth", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-core/index.ios.ts b/packages/firebase-core/index.ios.ts index 75e9c451..c0c522a6 100644 --- a/packages/firebase-core/index.ios.ts +++ b/packages/firebase-core/index.ios.ts @@ -234,6 +234,17 @@ export class FirebaseApp { } } +const launchQueue = []; + +declare const TNSFirebaseCore; + +const launchCallback = () => { + launchQueue.forEach((item) => item()); + launchQueue.splice(0); +}; + +TNSFirebaseCore.setOnAppFinishLaunchingCallback(launchCallback); + export class Firebase { constructor() { if (firebaseInstance) { @@ -352,21 +363,18 @@ export class Firebase { } resolve(fbApp); } catch (e) { - reject(new FirebaseError(e.message)) + reject(new FirebaseError(e.message)); } - } + }; if (!UIApplication.sharedApplication) { - Application.ios.addNotificationObserver( - UIApplicationDidFinishLaunchingNotification, - (notification) => { - initApp(); - } - ) + launchQueue.push(() => { + initApp(); + }); } else { initApp(); } - }) + }); } initializeAppWithPath(path: string, options: FirebaseOptions = null, config?: FirebaseConfig) { @@ -374,14 +382,13 @@ export class Firebase { const initApp = () => { try { if (path.startsWith('res://')) { - path = NSBundle.mainBundle.pathForResourceOfType(path.replace('res://', '').replace('.plist', ''), 'plist') + path = NSBundle.mainBundle.pathForResourceOfType(path.replace('res://', '').replace('.plist', ''), 'plist'); } else if (path.startsWith('~/')) { path = knownFolders.currentApp().path + '/' + path.replace('~/', ''); } const nativeOptions = FIROptions.alloc().initWithContentsOfFile(path); - if (options?.apiKey) { nativeOptions.APIKey = options.apiKey; } @@ -430,7 +437,6 @@ export class Firebase { nativeOptions.trackingID = options.trackingId; } - FIRApp.configureWithOptions(nativeOptions); const app = FIRApp.defaultApp(); @@ -445,20 +451,17 @@ export class Firebase { } resolve(fbApp); } catch (e) { - reject(new FirebaseError(e.message)) + reject(new FirebaseError(e.message)); } - } + }; if (!UIApplication.sharedApplication) { - Application.ios.addNotificationObserver( - UIApplicationDidFinishLaunchingNotification, - (notification) => { - initApp(); - } - ) + launchQueue.push(() => { + initApp(); + }); } else { initApp(); } - }) + }); } } diff --git a/packages/firebase-core/package.json b/packages/firebase-core/package.json index 5c8e61f2..9e3c6a54 100644 --- a/packages/firebase-core/package.json +++ b/packages/firebase-core/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-core", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Core", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-core/platforms/ios/src/TNSFirebaseCore.h b/packages/firebase-core/platforms/ios/src/TNSFirebaseCore.h new file mode 100644 index 00000000..460bdaa1 --- /dev/null +++ b/packages/firebase-core/platforms/ios/src/TNSFirebaseCore.h @@ -0,0 +1,7 @@ +#import +#import "UIApplicationDelegate+LaunchExtension.h" +typedef void(^LaunchCallback)(); +@interface TNSFirebaseCore: NSObject ++(LaunchCallback) onAppFinishLaunchingCallback; ++(void) setOnAppFinishLaunchingCallback:(LaunchCallback)callback; +@end diff --git a/packages/firebase-core/platforms/ios/src/TNSFirebaseCore.m b/packages/firebase-core/platforms/ios/src/TNSFirebaseCore.m new file mode 100644 index 00000000..d6d27bd9 --- /dev/null +++ b/packages/firebase-core/platforms/ios/src/TNSFirebaseCore.m @@ -0,0 +1,12 @@ +#import "TNSFirebaseCore.h" + +@implementation TNSFirebaseCore +static LaunchCallback _Nullable _onAppFinishLaunchingCallback; ++ (LaunchCallback)onAppFinishLaunchingCallback { + return _onAppFinishLaunchingCallback; +} + ++ (void)setOnAppFinishLaunchingCallback:(nullable LaunchCallback)callback { + _onAppFinishLaunchingCallback = callback; +} +@end diff --git a/packages/firebase-core/platforms/ios/src/TNSFirebaseCoreUmbrella.h b/packages/firebase-core/platforms/ios/src/TNSFirebaseCoreUmbrella.h new file mode 100644 index 00000000..ae484a4e --- /dev/null +++ b/packages/firebase-core/platforms/ios/src/TNSFirebaseCoreUmbrella.h @@ -0,0 +1,2 @@ +#import "TNSFirebaseCore.h" +#import "UIApplicationDelegate+LaunchExtension.h" \ No newline at end of file diff --git a/packages/firebase-core/platforms/ios/src/UIApplicationDelegate+LaunchExtension.h b/packages/firebase-core/platforms/ios/src/UIApplicationDelegate+LaunchExtension.h new file mode 100644 index 00000000..425a8def --- /dev/null +++ b/packages/firebase-core/platforms/ios/src/UIApplicationDelegate+LaunchExtension.h @@ -0,0 +1,5 @@ +#import + +@interface NSObject (TNSUIAppDelegateExt) +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions; +@end \ No newline at end of file diff --git a/packages/firebase-core/platforms/ios/src/UIApplicationDelegate+LaunchExtension.m b/packages/firebase-core/platforms/ios/src/UIApplicationDelegate+LaunchExtension.m new file mode 100644 index 00000000..9a9ddf58 --- /dev/null +++ b/packages/firebase-core/platforms/ios/src/UIApplicationDelegate+LaunchExtension.m @@ -0,0 +1,13 @@ +#import "UIApplicationDelegate+LaunchExtension.h" +#import "TNSFirebaseCore.h" +#import + +@implementation NSObject (TNSUIAppDelegateExt) +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions { + LaunchCallback callback = [TNSFirebaseCore onAppFinishLaunchingCallback]; + if(callback != nil){ + callback(); + } + return YES; +} +@end diff --git a/packages/firebase-core/platforms/ios/src/module.modulemap b/packages/firebase-core/platforms/ios/src/module.modulemap new file mode 100644 index 00000000..8c9fc9af --- /dev/null +++ b/packages/firebase-core/platforms/ios/src/module.modulemap @@ -0,0 +1,5 @@ + module TNSFirebaseCore { + umbrella header "TNSFirebaseCoreUmbrella.h" + export * + module * { export * } +} \ No newline at end of file diff --git a/packages/firebase-crashlytics/package.json b/packages/firebase-crashlytics/package.json index de77bf06..f9a1af44 100644 --- a/packages/firebase-crashlytics/package.json +++ b/packages/firebase-crashlytics/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-crashlytics", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Crashlytics", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-dynamic-links/package.json b/packages/firebase-dynamic-links/package.json index 4a078dba..5cb2fbe5 100644 --- a/packages/firebase-dynamic-links/package.json +++ b/packages/firebase-dynamic-links/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-dynamic-links", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Dynamic Links", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-firestore/package.json b/packages/firebase-firestore/package.json index d5588dbb..bd15802f 100644 --- a/packages/firebase-firestore/package.json +++ b/packages/firebase-firestore/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-firestore", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Firestore", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-functions/package.json b/packages/firebase-functions/package.json index 9be7785b..b3857770 100644 --- a/packages/firebase-functions/package.json +++ b/packages/firebase-functions/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-functions", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Functions", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-in-app-messaging/package.json b/packages/firebase-in-app-messaging/package.json index ccff9b0e..8cda4f6a 100644 --- a/packages/firebase-in-app-messaging/package.json +++ b/packages/firebase-in-app-messaging/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-in-app-messaging", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - In App Messaging", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-installations/package.json b/packages/firebase-installations/package.json index a9ff59f7..71624666 100644 --- a/packages/firebase-installations/package.json +++ b/packages/firebase-installations/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-installations", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Installations", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-messaging/package.json b/packages/firebase-messaging/package.json index 3a61ca2a..9ef525a2 100644 --- a/packages/firebase-messaging/package.json +++ b/packages/firebase-messaging/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-messaging", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Messaging", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessaging.swift b/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessaging.swift index d6a28211..3a3ec7a3 100644 --- a/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessaging.swift +++ b/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessaging.swift @@ -13,8 +13,7 @@ public class TNSFirebaseMessaging: NSObject { @objc public static var onMessageCallback: ((NSDictionary) -> Void)? = nil - public static var onTokenCallback: ((String) -> Void)? = nil - + @objc public static var onTokenCallback: ((String) -> Void)? = nil @objc public static func APNSTokenToString(_ tokenData: NSData)-> String { var token = "" diff --git a/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessagingLoader.h b/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessagingLoader.h index 3861d842..bb450d01 100644 --- a/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessagingLoader.h +++ b/packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessagingLoader.h @@ -1,5 +1,5 @@ #import #import -@interface TNSFirebaseMessagingLoader: NSObject +@interface TNSFirebaseCoreLoader: NSObject @end \ No newline at end of file diff --git a/packages/firebase-performance/package.json b/packages/firebase-performance/package.json index 2b39ffe2..929012a2 100644 --- a/packages/firebase-performance/package.json +++ b/packages/firebase-performance/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-performance", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Performancee", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-remote-config/package.json b/packages/firebase-remote-config/package.json index 2b06d05b..40cdf62a 100644 --- a/packages/firebase-remote-config/package.json +++ b/packages/firebase-remote-config/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-remote-config", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Remote Config", "main": "index", "typings": "index.d.ts", diff --git a/packages/firebase-storage/package.json b/packages/firebase-storage/package.json index 7981fc08..9f09eeca 100644 --- a/packages/firebase-storage/package.json +++ b/packages/firebase-storage/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/firebase-storage", - "version": "1.0.0", + "version": "1.0.1", "description": "NativeScript Firebase - Storage", "main": "index", "typings": "index.d.ts", diff --git a/workspace.json b/workspace.json index fd36e093..abf879d9 100644 --- a/workspace.json +++ b/workspace.json @@ -58,13 +58,15 @@ "ios": { "executor": "@nativescript/nx:build", "options": { - "platform": "ios" + "platform": "ios", + "noHmr": true } }, "android": { "executor": "@nativescript/nx:build", "options": { - "platform": "android" + "platform": "android", + "noHmr": true } }, "clean": {