我正在使用react-native
创建一个移动应用程序,我会安排本地通知,这些通知会在通知被触发时发出声音。我在PushNotificationIOS
中使用react-native
API来处理iOS
中的本地通知。到目前为止,我一直在使用react-native
版本0.24
,声音可以按预期播放。我最近更新到最新版本0.30
,现在收到通知时声音没有播放。我不确定什么是错的,因为没有任何改变w.r.t.从PushNotificationIOS
开始使用0.24
播放声音。我已经确认:
Copy Bundle Resources
react-native-sound
包播放声音文件,声音文件实际存在于应用中notification.getSound()
并得到了正确的名字。我甚至尝试通过将soundName
设置为default
来播放默认声音,但仍然没有声音。以下是我如何安排本地通知:
PushNotificationIOS.scheduleLocalNotification({
fireDate: time,
alertBody: alertBody,
soundName: 'default',
userInfo: info,
category: category
});
index.ios.js文件
class TestLocalNotification extends Component {
componentDidMount() {
PushNotificationIOS.requestPermissions()
}
scheduleLocalNotification = () => {
console.log('Scheduling local notification')
PushNotificationIOS.scheduleLocalNotification({
fireDate: Date.now() + 60000,
alertBody: 'Notificaiton',
soundName: 'default'
});
}
render() {
return (
<TouchableOpacity onPress={this.scheduleLocalNotification}>
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
</TouchableOpacity>
);
}
}
可以通过以下步骤重现问题
react-native init TestLocalNotification
index.ios.js
文件PushNotificaionIOS
TouchableOpacity
和react-native
运行该应用。点击文字Welcome to React Native
,然后按shift + cmd + h
转到主屏幕。观察一分钟后发出本地通知但没有播放声音。
请告知我如何调试和解决此问题。谢谢!