我在外部iPhone上测试,因为我知道推送通知在模拟器上不起作用。我的世博会令牌未被发送到我的Firebase数据库,因此我挖掘了代码并发现异步调用status
中的Permissions.askAsync(Permissions.NOTIFICATIONS)
变量返回为undetermined
。我在这个论坛上看到的所有回复都涉及这个问题来自模拟器,所以我很困惑为什么会这样。
以下是我基本上直接从文档中使用的相应代码:
import { Font, AppLoading, Permissions, Notifications } from 'expo';
和componentDidMount()
registerForPushNotificationsAsync = async (user) => { const { status: existingStatus } = await Permissions.getAsync( Permissions.NOTIFICATIONS ); let finalStatus = existingStatus; // only ask if permissions have not already been determined, because // iOS won't necessarily prompt the user a second time. if (existingStatus !== 'granted') { // Android remote notification permissions are granted during the app // install, so this will only ask on iOS const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS); console.log(status); finalStatus = status; } // Stop here if the user did not grant permissions if (finalStatus !== 'granted') { return; } // Get the token that uniquely identifies this device let token = await Notifications.getExpoPushTokenAsync(); alert(token); var updates = {} updates['/expoToken'] = token; database.ref('users').child(user.uid).update(updates) }
这是Permissions.getAsync
正如你所看到的,我一直在控制台记录状态变量,它在那时显示未确定。
我还能如何帮助调试此问题?谢谢!