我使用OneSignal sdk进行反应原生。当应用程序处于焦点时,我尝试禁用内部警报。你知道怎么做吗?
这是我的代码:
OneSignal.configure({
onIdsAvailable: function (device) {
console.log('UserId = ', device.userId);
console.log('PushToken = ', device.pushToken);
getUserId(device.userId);
},
onNotificationReceived: function (notification) {
OneSignal.checkPermissions((permissions) => {
console.log(permissions);
});
OneSignal.inFocusDisplaying(0);
},
onNotificationOpened: function(message, data, isActive) {
console.log("MS TYPE", message);
switch(message.notification.payload.additionalData.type) {
case '1':
Actions.messenger({id: message.notification.payload.additionalData.userID});
break;
case '2':
Actions.overview();
break;
}
}
});
答案 0 :(得分:2)
我认为代码中的问题是您放置OneSignal.inFocusDisplaying(0);
您需要将其放在componentWillMount
上
componentWillMount () {
OneSignal.addEventListener('received', this.onReceived.bind(this))
OneSignal.addEventListener('opened', this.onOpened)
OneSignal.addEventListener('registered', this.onRegistered)
OneSignal.addEventListener('ids', this.onIds.bind(this))
// Set inFocusDisplaying to prevent the default push notification alert when the is in focus
// Android ONLY
OneSignal.inFocusDisplaying(0)
}