您好,我创建了一个新的 17.1 ReactNative 应用程序并合并了 OneSignal。
根据示例,它应该订阅,但没有。
我也在物理设备上对此进行测试。
此操作运行,没有错误,我第一次收到允许通知的提示。
但是用户没有订阅。
我尝试添加
OneSignal.sendTag('my app id', true);
但收到错误 sendTag 未定义
我的代码看起来像
const App = () => {
// Remove this method to stop OneSignal Debugging
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
// OneSignal Initialization
OneSignal.initialize("ONESIGNAL_APP_ID");
// requestPermission will show the native iOS or Android notification permission prompt.
// We recommend removing the following code and instead using an In-App Message to prompt for notification permission
OneSignal.Notifications.requestPermission(true);
// Method for listening for notification clicks
OneSignal.Notifications.addEventListener('click', (event) => {
console.log('OneSignal: notification clicked:', event);
});
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
backgroundColor={backgroundStyle.backgroundColor}
/>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Button
title="Press me"
onPress={subscribe}
/>
<LearnMoreLinks />
</View>
</ScrollView>
</SafeAreaView>
);
};
感谢您的帮助
我用
OneSignal.setAppId("ONESIGNAL_APP_ID")
而不是
OneSignal.initialize("ONESIGNAL_APP_ID")
将用户/电话分配给 OneSignal 应用程序。也许这会有所帮助!