Skip to content

Commit ef94e63

Browse files
committed
fix(messaging): ios onNotificationTap
fixes: #42
1 parent dc3fd90 commit ef94e63

File tree

30 files changed

+146
-46
lines changed

30 files changed

+146
-46
lines changed

Diff for: apps/demo-angular/nativescript.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { NativeScriptConfig } from '@nativescript/core';
22

33
export default {
4-
id: 'org.nativescript.plugindemoangular',
4+
// id: 'org.nativescript.plugindemoangular',
5+
id: 'io.github.triniwiz.nativescript.firebasedemo',
56
appResourcesPath: '../../tools/assets/App_Resources',
67
android: {
78
v8Flags: '--expose_gc',

Diff for: apps/demo-angular/src/app.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Component } from '@angular/core';
2-
2+
import { AppService } from './app.service';
33
@Component({
44
selector: 'demo-app',
55
template: `<GridLayout>
66
<page-router-outlet></page-router-outlet>
77
</GridLayout>`,
88
})
9-
export class AppComponent {}
9+
export class AppComponent {
10+
constructor(appService: AppService){}
11+
}

Diff for: apps/demo-angular/src/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { NativeScriptModule } from '@nativescript/angular';
44
import { AppComponent } from './app.component';
55
import { AppRoutingModule } from './app-routing.module';
66
import { HomeComponent } from './home.component';
7+
import { AppService } from './app.service';
78

89
@NgModule({
910
schemas: [NO_ERRORS_SCHEMA],
1011
declarations: [AppComponent, HomeComponent],
1112
bootstrap: [AppComponent],
1213
imports: [NativeScriptModule, AppRoutingModule],
14+
providers: [AppService]
1315
})
1416
export class AppModule {}

Diff for: apps/demo-angular/src/app.service.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Injectable } from '@angular/core';
2+
import { firebase } from '@nativescript/firebase-core';
3+
import '@nativescript/firebase-messaging';
4+
5+
@Injectable()
6+
export class AppService {
7+
constructor() {
8+
const messaging = firebase().messaging();
9+
messaging.onToken((token) => {
10+
console.log('Firebase onToken', token);
11+
});
12+
messaging.onMessage((message) => {
13+
console.log('Firebase onMessage', message);
14+
});
15+
16+
messaging.onNotificationTap((message) => {
17+
console.log('Firebase onNotificationTap', message);
18+
});
19+
20+
}
21+
}

Diff for: apps/demo-angular/src/main.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
import { runNativeScriptAngularApp, platformNativeScript } from '@nativescript/angular';
22
import { AppModule } from './app.module';
3+
import { firebase } from '@nativescript/firebase-core';
4+
import { Application } from '@nativescript/core';
5+
6+
Application.on('launch', (args) => {
7+
console.log('launch');
8+
});
9+
10+
firebase()
11+
.initializeApp()
12+
.then((done) => {
13+
console.log('initializeApp');
14+
});
15+
16+
const messaging = firebase().messaging();
17+
18+
messaging
19+
.requestPermission()
20+
.then(() => {
21+
console.log('requestPermission', 'done');
22+
messaging.registerDeviceForRemoteMessages().catch((e) => {
23+
console.error('registerDeviceForRemoteMessages', e);
24+
});
25+
})
26+
.catch((e) => {
27+
console.error('requestPermission', e);
28+
});
329

430
runNativeScriptAngularApp({
5-
appModuleBootstrap: () => platformNativeScript().bootstrapModule(AppModule),
6-
});
31+
appModuleBootstrap: () => platformNativeScript().bootstrapModule(AppModule),
32+
});

Diff for: packages/firebase-admob/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-admob",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Admob",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-analytics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-analytics",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Analytics",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-app-check/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-app-check",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - App Check",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-auth/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-auth",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Auth",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-core/index.ios.ts

+24-21
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ export class FirebaseApp {
234234
}
235235
}
236236

237+
const launchQueue = [];
238+
239+
declare const TNSFirebaseCore;
240+
241+
const launchCallback = () => {
242+
launchQueue.forEach((item) => item());
243+
launchQueue.splice(0);
244+
};
245+
246+
TNSFirebaseCore.setOnAppFinishLaunchingCallback(launchCallback);
247+
237248
export class Firebase {
238249
constructor() {
239250
if (firebaseInstance) {
@@ -352,36 +363,32 @@ export class Firebase {
352363
}
353364
resolve(fbApp);
354365
} catch (e) {
355-
reject(new FirebaseError(e.message))
366+
reject(new FirebaseError(e.message));
356367
}
357-
}
368+
};
358369

359370
if (!UIApplication.sharedApplication) {
360-
Application.ios.addNotificationObserver(
361-
UIApplicationDidFinishLaunchingNotification,
362-
(notification) => {
363-
initApp();
364-
}
365-
)
371+
launchQueue.push(() => {
372+
initApp();
373+
});
366374
} else {
367375
initApp();
368376
}
369-
})
377+
});
370378
}
371379

372380
initializeAppWithPath(path: string, options: FirebaseOptions = null, config?: FirebaseConfig) {
373381
return new Promise((resolve, reject) => {
374382
const initApp = () => {
375383
try {
376384
if (path.startsWith('res://')) {
377-
path = NSBundle.mainBundle.pathForResourceOfType(path.replace('res://', '').replace('.plist', ''), 'plist')
385+
path = NSBundle.mainBundle.pathForResourceOfType(path.replace('res://', '').replace('.plist', ''), 'plist');
378386
} else if (path.startsWith('~/')) {
379387
path = knownFolders.currentApp().path + '/' + path.replace('~/', '');
380388
}
381389

382390
const nativeOptions = FIROptions.alloc().initWithContentsOfFile(path);
383391

384-
385392
if (options?.apiKey) {
386393
nativeOptions.APIKey = options.apiKey;
387394
}
@@ -430,7 +437,6 @@ export class Firebase {
430437
nativeOptions.trackingID = options.trackingId;
431438
}
432439

433-
434440
FIRApp.configureWithOptions(nativeOptions);
435441

436442
const app = FIRApp.defaultApp();
@@ -445,20 +451,17 @@ export class Firebase {
445451
}
446452
resolve(fbApp);
447453
} catch (e) {
448-
reject(new FirebaseError(e.message))
454+
reject(new FirebaseError(e.message));
449455
}
450-
}
456+
};
451457
if (!UIApplication.sharedApplication) {
452-
Application.ios.addNotificationObserver(
453-
UIApplicationDidFinishLaunchingNotification,
454-
(notification) => {
455-
initApp();
456-
}
457-
)
458+
launchQueue.push(() => {
459+
initApp();
460+
});
458461
} else {
459462
initApp();
460463
}
461-
})
464+
});
462465
}
463466
}
464467

Diff for: packages/firebase-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-core",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Core",
55
"main": "index",
66
"typings": "index.d.ts",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <Foundation/Foundation.h>
2+
#import "UIApplicationDelegate+LaunchExtension.h"
3+
typedef void(^LaunchCallback)();
4+
@interface TNSFirebaseCore: NSObject
5+
+(LaunchCallback) onAppFinishLaunchingCallback;
6+
+(void) setOnAppFinishLaunchingCallback:(LaunchCallback)callback;
7+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import "TNSFirebaseCore.h"
2+
3+
@implementation TNSFirebaseCore
4+
static LaunchCallback _Nullable _onAppFinishLaunchingCallback;
5+
+ (LaunchCallback)onAppFinishLaunchingCallback {
6+
return _onAppFinishLaunchingCallback;
7+
}
8+
9+
+ (void)setOnAppFinishLaunchingCallback:(nullable LaunchCallback)callback {
10+
_onAppFinishLaunchingCallback = callback;
11+
}
12+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#import "TNSFirebaseCore.h"
2+
#import "UIApplicationDelegate+LaunchExtension.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface NSObject (TNSUIAppDelegateExt) <UIApplicationDelegate>
4+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions;
5+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import "UIApplicationDelegate+LaunchExtension.h"
2+
#import "TNSFirebaseCore.h"
3+
#import <objc/runtime.h>
4+
5+
@implementation NSObject (TNSUIAppDelegateExt)
6+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions {
7+
LaunchCallback callback = [TNSFirebaseCore onAppFinishLaunchingCallback];
8+
if(callback != nil){
9+
callback();
10+
}
11+
return YES;
12+
}
13+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module TNSFirebaseCore {
2+
umbrella header "TNSFirebaseCoreUmbrella.h"
3+
export *
4+
module * { export * }
5+
}

Diff for: packages/firebase-crashlytics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-crashlytics",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Crashlytics",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-dynamic-links/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-dynamic-links",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Dynamic Links",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-firestore/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-firestore",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Firestore",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-functions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-functions",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Functions",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-in-app-messaging/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-in-app-messaging",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - In App Messaging",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-installations/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-installations",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Installations",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-messaging/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-messaging",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Messaging",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-messaging/platforms/ios/src/TNSFirebaseMessaging.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public class TNSFirebaseMessaging: NSObject {
1313

1414
@objc public static var onMessageCallback: ((NSDictionary) -> Void)? = nil
1515

16-
public static var onTokenCallback: ((String) -> Void)? = nil
17-
16+
@objc public static var onTokenCallback: ((String) -> Void)? = nil
1817

1918
@objc public static func APNSTokenToString(_ tokenData: NSData)-> String {
2019
var token = ""
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import <Foundation/Foundation.h>
22
#import <UIKit/UIKit.h>
33

4-
@interface TNSFirebaseMessagingLoader: NSObject
4+
@interface TNSFirebaseCoreLoader: NSObject
55
@end

Diff for: packages/firebase-performance/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-performance",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Performancee",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-remote-config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-remote-config",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Remote Config",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-storage/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-storage",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "NativeScript Firebase - Storage",
55
"main": "index",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)