问题描述
这是我的代码,我正在使用钩子并且也已经尝试使用类组件,但是我遇到了一些错误
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)}
类型错误:_reactNativeOnesignal.default.init 不是函数。 (在'_reactNativeOnesignal.default.init('a6a1f13d-8823-4d98-86c9-d99aef433795')'中,'_reactNativeOnesignal.default.init'未定义)
解决方法
我已经解决了这个问题,结果 One Signal 在新版本中改变了他们的方法。所以现在功能已经不同了。谢谢大家。