我需要如何解决错误 ini 一个信号反应本机
How I need to solve error ini one signal react native
这是我的代码,我正在使用钩子并且也已经尝试使用 class 组件,但是我遇到了一些错误
useEffect(() => {
OneSignal.setLogLevel(6, 0);
OneSignal.init('a6a1f13d-8823-4d98-86c9-d99aef433795', {
kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInAppLaunchURL: false,
kOSSettingsKeyInFocusDisplayOption: 2,
});
OneSignal.inFocusDisplaying(2);
OneSignal.addEventListener('received', onReceived);
OneSignal.addEventListener('opened', onOpened);
OneSignal.addEventListener('ids', onIds);
return () => {
OneSignal.removeEventListener('received', onReceived);
OneSignal.removeEventListener('opened', onOpened);
OneSignal.removeEventListener('ids', onIds);
}}, []);
const onReceived = (notification) => {
console.log('Notification received: ', notification);}
const onOpened = (openResult) => {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult)}
const onIds = (device) => {
console.log('Device info: ', device)}
TypeError: _reactNativeOnesignal.default.init 不是函数。 (在'_reactNativeOnesignal.default.init('a6a1f13d-8823-4d98-86c9-d99aef433795')'中,'_reactNativeOnesignal.default.init'是未定义的)
我已经解决了这个问题,原来 One Signal 用新版本改变了他们的方法。所以现在功能已经不同了。谢谢大家
这是我的代码,我正在使用钩子并且也已经尝试使用 class 组件,但是我遇到了一些错误
useEffect(() => {
OneSignal.setLogLevel(6, 0);
OneSignal.init('a6a1f13d-8823-4d98-86c9-d99aef433795', {
kOSSettingsKeyAutoPrompt: false,
kOSSettingsKeyInAppLaunchURL: false,
kOSSettingsKeyInFocusDisplayOption: 2,
});
OneSignal.inFocusDisplaying(2);
OneSignal.addEventListener('received', onReceived);
OneSignal.addEventListener('opened', onOpened);
OneSignal.addEventListener('ids', onIds);
return () => {
OneSignal.removeEventListener('received', onReceived);
OneSignal.removeEventListener('opened', onOpened);
OneSignal.removeEventListener('ids', onIds);
}}, []);
const onReceived = (notification) => {
console.log('Notification received: ', notification);}
const onOpened = (openResult) => {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult)}
const onIds = (device) => {
console.log('Device info: ', device)}
TypeError: _reactNativeOnesignal.default.init 不是函数。 (在'_reactNativeOnesignal.default.init('a6a1f13d-8823-4d98-86c9-d99aef433795')'中,'_reactNativeOnesignal.default.init'是未定义的)
我已经解决了这个问题,原来 One Signal 用新版本改变了他们的方法。所以现在功能已经不同了。谢谢大家