I followed the android example installation, and it registers correctly and receives the notification correctly while the app is in killed state or on background. but while on foreground nothing seems to fire.
import React, { Component } from 'react'
import {
View,
Alert,
Image,
TouchableOpacity,
ImageBackground,
Linking,
AsyncStorage,
StatusBar,
Dimensions,
NativeEventEmitter
} from 'react-native'
//-----------
const NotificationHub = require('react-native-azurenotificationhub');
const PushNotificationEmitter = new NativeEventEmitter(NotificationHub);
const NOTIF_REGISTER_AZURE_HUB_EVENT = 'azureNotificationHubRegistered';
const NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT = 'azureNotificationHubRegistrationError';
const DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
const connectionString = '*****; // The Notification Hub connection string
const hubName = '*****'; // The Notification Hub name
const senderID = '*****'; // The Sender ID from the Cloud Messaging tab of the Firebase console
const tags = ['test']; // The set of tags to subscribe to
//-----------
export default class LoginView extends Component {
constructor(props) {
super(props)
PushNotificationEmitter.addListener(DEVICE_NOTIF_EVENT, this._onRemoteNotification);
}
register() {
PushNotificationEmitter.addListener(NOTIF_REGISTER_AZURE_HUB_EVENT, this._onAzureNotificationHubRegistered);
PushNotificationEmitter.addListener(NOTIF_AZURE_HUB_REGISTRATION_ERROR_EVENT, this._onAzureNotificationHubRegistrationError);
NotificationHub.register({connectionString, hubName, senderID, tags})
.catch(reason => console.warn(reason));
}
render() {
this.register();
return (
<View>
Example
</View>
)
}
_onAzureNotificationHubRegistered(registrationID) {
console.warn('RegistrationID: ' + registrationID);
}
_onAzureNotificationHubRegistrationError(error) {
console.warn('Error: ' + error);
}
_onRemoteNotification(notification) {
console.warn('Notification received: ' + notification);
}
}