我使用的是react-nate-push-通知库。我可以让通知随着振动和声音一起出现......但是问题是它一直重复并且不会停止。
我连续收到20个相同的通知。有人知道为什么会这样吗?
请参阅下面的代码
import PushNotification from 'react-native-push-notification';
constructor(props) {
super(props);
PushNotification.configure({
onNotification: function(notification) {
console.log('NOTIFICATION:', notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
popInitialNotification: true,
requestPermissions: true,
});
runPushNotification = () => {
PushNotification.localNotification({
title: 'title'
message: 'message',
playSound: true,
soundName: 'sound.mp3',
autoCancel: true,
vibrate: true,
vibration: 300,
actions: '["Yes", "No"]',
onlyAlertOnce: true,
});
};
对我来说,这是消除重复类型解决了问题
//repeatType: 'day', // (optional) Repeating interval. Check 'Repeating
PushNotification.localNotification({
/* Android Only Properties */
channelId: '767888', // (required) channelId, if the channel doesn't exist, notification will not trigger.
ticker: 'My Notification Ticker', // (optional)
showWhen: true, // (optional) default: true
autoCancel: true, // (optional) default: true
largeIcon: 'ic_launcher', // (optional) default: "ic_launcher". Use "" for no large icon.
largeIconUrl: 'https://www.example.tld/picture.jpg', // (optional) default: undefined
smallIcon: 'ic_notification', // (optional) default: "ic_notification" with fallback for "ic_launcher". Use "" for default small icon.
bigText: 'My big text that will be shown when notification is expanded', // (optional) default: "message" prop
subText: 'This is a subText', // (optional) default: none
bigPictureUrl: 'https://www.example.tld/picture.jpg', // (optional) default: undefined
bigLargeIcon: 'ic_launcher', // (optional) default: undefined
bigLargeIconUrl: 'https://www.example.tld/bigicon.jpg', // (optional) default: undefined
color: 'red', // (optional) default: system default
vibrate: true, // (optional) default: true
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
tag: 'some_tag', // (optional) add tag to message
group: 'group', // (optional) add group to message
groupSummary: false, // (optional) set this notification to be the group summary for a group of notifications, default: false
ongoing: false, // (optional) set whether this is an "ongoing" notification
priority: 'high', // (optional) set notification priority, default: high
visibility: 'private', // (optional) set notification visibility, default: private
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear). should be used in combine with `com.dieam.reactnativepushnotification.notification_foreground` setting
shortcutId: 'shortcut-id', // (optional) If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut, default undefined
onlyAlertOnce: false, // (optional) alert will open only once with sound and notify, default: false
when: null, // (optional) Add a timestamp (Unix timestamp value in milliseconds) pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
usesChronometer: false, // (optional) Show the `when` field as a stopwatch. Instead of presenting `when` as a timestamp, the notification will show an automatically updating display of the minutes and seconds since when. Useful when showing an elapsed time (like an ongoing phone call), default: false.
timeoutAfter: null, // (optional) Specifies a duration in milliseconds after which this notification should be canceled, if it is not already canceled, default: null
messageId: 'google:message_id', // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module.
actions: ['Yes', 'No'], // (Android only) See the doc for notification actions to know more
invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
/* iOS only properties */
category: '', // (optional) default: empty string
/* iOS and Android properties */
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
title: 'My Notification Title', // (optional)
message: 'My Notification Message', // (required)
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
playSound: false, // (optional) default: true
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
//repeatType: 'day', // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
});
``
对于未来的观众来说,如果你收到通知,有两种方式可以实现,一种是来自外部服务器的推送通知,另一种是从你的应用程序自己的代码创建的本地通知。
如果您收到推送通知,那么您需要检查您的服务器端逻辑,看看您没有触发它们太多次。
如果这些是本地通知,请在代码中搜索您调用通知的任何位置。
做这两件事应该会导致它被过度调用。
我有一个Android应用程序,可以通过Firebase接收通知。这些通知由网站上的用户操作触发。然后,我们的API向Firebase发送通知请求。 然而,最近我遇到了一个问题,我的应用程序一直不停地接收通知。对于直接通知和主题消息,这似乎都在发生。起初我以为是API卡在某种循环中,但事实并非如此,因为我直接从Firebase控制台发送的通知也会发生这种情况。我自己的理论是Firebase认为通知
所以我做了一个应用程序,它使用很多线程/可运行(我们说的是300多线程)来下载很多内容。这在模拟器和一些设备如三星Galaxy S3上工作很好,但由于某些原因,在HTC One和其他设备上,我的线程或服务在没有任何通知、警告和错误的情况下被停止。应用程序继续运行,但启动所有线程的任何服务/线程都只是终止。 我所尝试的是: null 来自HTC One的Logcat,带有START_STICKY和s
如果我试图通过模拟器运行我的应用程序,它会一直停止。。我该怎么修?这是我的日志: 引起:java.lang.IllegalStateExcema:你需要使用一个主题。AppCompat主题(或后代)与此活动。 这是第35行:userEmail=findviewbyd(R.id.email);xml文件中的id是电子邮件 以下是mainactivity xml文件:
通知通道的新代码在旧的和最新的奥利奥设备上运行良好,但当我在API 28(android P)设备上测试时,它没有在通知栏中显示通知,这是我用来启动前台通知的行。
goodmornig,我对在Android Studio上创建数据库有一个问题。代码没有问题,但应用程序说“不幸停止”。我该如何解决这个问题呢? 还有另一个activity
我有两个装置。一个是运行API26,另一个是API21。我正在使用Googles firebase进行通知。API26设备不会收到推送通知,除非我先打开应用程序。然后它接收一切都很好。我不需要首先打开应用程序来接收API27设备上的推送通知。有什么想法,如何总是收到推送,即使没有打开应用程序?我希望通知到达用户只需打开他们的电话。