Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ firebaseDb.on('readByQueryEndingAtValue', function (eventPath, newMessages) {

* when you don't want to receive events for particular path anymore, you need to detach listener

```
```JavaScript
var firebaseDb = require("Firebase/Database");
var usersPath = 'users';
// say you subscribed to some path earlier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
"Includes": [
"Common.uno:Source",
"JS.uno:Source",

"Android/Impl.uno:Source",
"iOSImpl.uno:Source",
"Android/Impl.cpp.uxl:Extensions",
"Android/PushNotificationReceiver.java:Java:android",
"Android/PushNotificationIDService.java:Java:android",
"iOSFirebaseNotificationCallbacks.h:ObjCHeader:iOS",
"iOSFirebaseNotificationCallbacks.mm:ObjCSource:iOS",
"Android/Assets/DefaultIcon.png:File"
]
}
10 changes: 10 additions & 0 deletions src/Firebase.Notifications.Android/JS.uno
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Firebase.Notifications
public sealed class NotificationModule : NativeEventEmitterModule
{
static readonly NotificationModule _instance;
readonly iOSImpl _iOSImpl;
static NativeEvent _onRegistrationSucceedediOS;

public NotificationModule()
: base(true,
Expand All @@ -35,6 +37,8 @@ namespace Firebase.Notifications
if (_instance != null) return;
Resource.SetGlobalKey(_instance = this, "Firebase/Notifications");

_iOSImpl = new iOSImpl();

// Old-style events for backwards compatibility
var onReceivedMessage = new NativeEvent("onReceivedMessage");
var onRegistrationFailed = new NativeEvent("onRegistrationFailed");
Expand All @@ -55,6 +59,8 @@ namespace Firebase.Notifications
AddMember(onRegistrationFailed);
AddMember(new NativeFunction("clearBadgeNumber", ClearBadgeNumber));
AddMember(new NativeFunction("clearAllNotifications", ClearAllNotifications));
_onRegistrationSucceedediOS = new NativeEvent("onRegistrationSucceedediOS");
AddMember(_onRegistrationSucceedediOS);

Firebase.Notifications.NotificationService.ReceivedNotification += OnReceivedNotification;
Firebase.Notifications.NotificationService.RegistrationSucceeded += OnRegistrationSucceeded;
Expand Down Expand Up @@ -83,6 +89,10 @@ namespace Firebase.Notifications
Emit("registrationSucceeded", message);
}

static void OnRegistrationSucceedediOS(string message) {
_onRegistrationSucceedediOS.RaiseAsync(message);
}

/**
@scriptevent error
@param message A backend specific reason for the failure.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>
#include <Firebase/Firebase.h>

@interface FireNotificationCallbacks : NSObject<FIRMessagingDelegate>
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <iOSFirebaseNotificationCallbacks.h>
#include <@{Firebase.Notifications.NotificationModule:Include}>
#include <@{ObjC.Object:Include}>
#include <uObjC.Foreign.h>

@implementation FireNotificationCallbacks : NSObject


- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
NSLog(@"FCM registration token: %@", fcmToken);

@{Firebase.Notifications.NotificationModule.OnRegistrationSucceedediOS(string):Call(fcmToken)};
}

@end
35 changes: 35 additions & 0 deletions src/Firebase.Notifications.Android/iOSImpl.uno
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Uno;
using Uno.UX;
using Uno.Collections;
using Uno.Compiler.ExportTargetInterop;
using Fuse;
using Fuse.Triggers;
using Uno.Threading;

namespace Firebase.Notifications
{
[Require("Cocoapods.Podfile.Target", "pod 'Firebase/Messaging'")]
[extern(iOS) Require("Source.Include", "iOSFirebaseNotificationCallbacks.h")]
[Require("Source.Include", "Firebase/Firebase.h")]

public class iOSImpl
{
extern(ios) static internal ObjC.Object _iosDelegate;

public iOSImpl() {
Start();
}

extern(!iOS)
public void Start() { }

[Foreign(Language.ObjC)]
extern(iOS)
public void Start()
@{
FireNotificationCallbacks* fireCB = [[FireNotificationCallbacks alloc] init];
@{_iosDelegate:Set(fireCB)};
[FIRMessaging messaging].delegate = (id<FIRMessagingDelegate>)fireCB;
@}
}
}