React native 在迭代之前,等待异步函数完成

React native 在迭代之前,等待异步函数完成,react-native,promise,cross-platform,react-native-ios,react-native-cli,React Native,Promise,Cross Platform,React Native Ios,React Native Cli,我有一个“for”循环,一次点击按钮最多可以设置10个警报,在安卓系统上它工作得很好,没有任何问题,但在iOS系统上它只设置了循环中的最后一个警报,即使它在控制台中打印了10次“SUCCESS”消息。经过一些测试(在每次迭代中添加超时),我相信循环在设置警报之前正在迭代。我尝试在“ReactNative.scheduleAlarm”之前添加“await”,但它给出了一个错误,即“不能在异步函数之外使用await关键字”。那么,在迭代之前,我可以做些什么来等待schedule alarm函数完成呢

我有一个“for”循环,一次点击按钮最多可以设置10个警报,在安卓系统上它工作得很好,没有任何问题,但在iOS系统上它只设置了循环中的最后一个警报,即使它在控制台中打印了10次“SUCCESS”消息。经过一些测试(在每次迭代中添加超时),我相信循环在设置警报之前正在迭代。我尝试在“ReactNative.scheduleAlarm”之前添加“await”,但它给出了一个错误,即“不能在异步函数之外使用await关键字”。那么,在迭代之前,我可以做些什么来等待schedule alarm函数完成呢

我正在使用“react native alarm notification”库来管理警报,我使用的是RN 0.59.5

for (i = index; i < this.props.prayers.PrayerTimes.length; i++ ){
         fire_time = this.props.prayers.PrayerTimes[i][field.key]
         fire_datee = this.props.prayers.PrayerTimes[i].date
                            
         ReactNativeAN.scheduleAlarm({
                 title: PrayersStr[field.key],
                 message: " ",
                 tag: field.key,
                 color: "white",
                 channel: "my_channel_id",
                 small_icon: "ic_launcher",
                 loop_sound: "true",
                 sound_name: sound,
                 fire_date: moment(fire_datee, 'DD/MM/YYYY').format('DD-MM-YYYY') + ' ' + fire_time
                     }).then(res => {
                         console.log("SUCCESS")
                         if (this.props.alarms == null){
                            Identity.setAlarms({ [field.key]: true })
                          } else {
                            if(this.props.alarms[field.key] != true){
                             Identity.setAlarms({ ...this.props.alarms, [field.key]: true })
                                }
                              }
                        }).catch(e => {
                                console.log('error', e);
                              });

                            
                          }
for(i=index;i{
console.log(“成功”)
如果(this.props.alarms==null){
Identity.setAlarms({[field.key]:true})
}否则{
if(this.props.alarms[field.key]!=true){
Identity.setAlarms({…this.props.alarms,[field.key]:true})
}
}
}).catch(e=>{
console.log('error',e);
});
}