React native 反应本机推送通知-本地通知在Android上不起作用
有人能告诉我哪里出了问题吗。 从我在上看到的……如果您只使用本地通知并使用自动链接,则无需对Android特定文件进行任何修改……除了添加React native 反应本机推送通知-本地通知在Android上不起作用,react-native,react-native-android,react-native-push-notification,React Native,React Native Android,React Native Push Notification,有人能告诉我哪里出了问题吗。 从我在上看到的……如果您只使用本地通知并使用自动链接,则无需对Android特定文件进行任何修改……除了添加googlePlayServicesVersion=“”//默认值:“+”到Android/build.gradle…和到AndroidManifest.xml 下面是我的主要源代码 PushNotification.configure({ // (optional) Called when Token is generated (iOS and Andr
googlePlayServicesVersion=“”//默认值:“+”
到Android/build.gradle
…和
到AndroidManifest.xml
下面是我的主要源代码
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
console.log('onRegister token:', token);
},
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: function(notification) {
console.log('onNotification:', notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
// Should the initial notification be popped automatically
popInitialNotification: true,
requestPermissions: true,
});
userNowInactive = () => {
this.showNotification();
}
showNotification = () => {
PushNotification.localNotification({
//ios and android properties
title: 'Face2Face: Beacon Timer Expired',
message: 'Perhaps set your beacon timer for another hour?',
playSound: true,
soundName: 'sound.mp3',
//android only properties
channelId: 'your-channel-id',
autoCancel: true,
// largeIcon: 'ic_launcher',
// smallIcon: 'ic_launcher',
bigText: 'Face2Face: Beacon Timer Expired',
subText: 'Perhaps set your beacon timer for another hour?',
vibrate: true,
vibration: 300,
priority: 'high',
//ios only properties...is there any?
});
};
你创建了一个频道吗?
看来你需要创建一个让它工作
要使用通道,请在启动时创建它们,并将匹配的channelId传递给PushNotification.localNotification或PushNotification.localNotificationSchedule
PushNotification.createChannel(
{
channelId: "channel-id", // (required)
channelName: "My channel", // (required)
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
playSound: false, // (optional) default: true
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: 4, // (optional) default: 4. Int value of the Android notification importance
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
},
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
);
我可以看一下整个代码文件吗?是的,谢谢。这是正确的答案。频道必须是libraby最近的强制性部分,因为它在“npm安装”之前工作。我想教训是每次升级库时都要仔细检查每个库的功能