Я использовал функцию уведомлений о реактиве-native-azurenotificationhub, выполняющую pu sh, она работает, за исключением некоторого поведения из моего ожидаемого.
Я мог получить окно уведомлений при получении уведомления, но onRemoteNotification не быть запущенным.
Я ожидаю, что поведение будет получено Уведомление -> всплывающее уведомление консоли -> окно с подсказкой
Вот мой код, как я могу это сделать?
import { AsyncStorage, Alert } from "react-native";
import NotificationHub from "react-native-azurenotificationhub/index.ios";
import * as Permissions from "expo-permissions";
import key from "../../private/key";
const IOS = {
connectionString: key.azureConnectionString,
hubName: key.azureHubName,
requestPermissions: async function() {
NotificationHub.addEventListener("register", this._onRegistered);
NotificationHub.addEventListener(
"registrationError",
this._onRegistrationError
);
NotificationHub.addEventListener(
"registerAzureNotificationHub",
this._onAzureNotificationHubRegistered
);
NotificationHub.addEventListener(
"azureNotificationHubRegistrationError",
this._onAzureNotificationHubRegistrationError
);
debugger;
NotificationHub.addEventListener(
"notification",
this._onRemoteNotification
);
NotificationHub.addEventListener(
"localNotification",
this._onLocalNotification
);
await NotificationHub.requestPermissions();
},
PNregister: async function() {
const token = await AsyncStorage.getItem(key.PNToken);
NotificationHub.register(token, {
connectionString: this.connectionString,
hubName: this.hubName,
tags: [token]
});
},
PNunregister: async function() {
try {
await AsyncStorage.removeItem(key.PNToken);
await NotificationHub.abandonPermissions();
} catch (error) {
console.log(error);
}
},
PNCleanBadge: function() {
NotificationHub.getApplicationIconBadgeNumber((num) => {
if (num > 0) {
NotificationHub.setApplicationIconBadgeNumber(0);
}
});
},
_onRegistered: async function(deviceToken) {
await AsyncStorage.setItem(key.PNToken, deviceToken);
},
_onRegistrationError: function(error) {
Alert.alert(
"Failed To Register For Remote Push",
`Error (${error.code}): ${error.message}`,
[
{
text: "Dismiss",
onPress: null
}
]
);
},
_onAzureNotificationHubRegistered: async function(registrationInfo) {
AsyncStorage.setItem(
key.PNRegistrationInfo,
JSON.stringify(registrationInfo)
);
},
_onAzureNotificationHubRegistrationError: function(error) {
Alert.alert(
"Failed To Register For Azure Notification Hub",
`Error (${error.code}): ${error.message}`,
[
{
text: "Dismiss",
onPress: null
}
]
);
},
_onRemoteNotification: function(notification) {
console.log(notification);
Alert.alert(
"Push Notification Received",
"Alert message: " + notification.getMessage(),
[
{
text: "Dismiss",
onPress: null
}
]
);
},
_onLocalNotification: function(notification) {
console.log(notification);
// Note notification will be object for iOS
Alert.alert(
"Local Notification Received",
"Alert message: " + notification.getMessage(),
[
{
text: "Dismiss",
onPress: null
}
]
);
}
};
export default IOS;