我在App Store上有一个独立的(Expo)应用程序。当我尝试获得Expo Push Token时,我收到此错误:
Error: The device was unable to register for remote notifications with Apple
我没有在iOS模拟器上运行它。这些是来自在App Store上运行应用程序的真正iPhone。
这是InvalidCredentials
错误吗?我该怎么做才能解决这个问题?
我已经扫描了堆栈溢出并尝试了这种方法的许多重新排列,但没有任何作用。
这种方法似乎也适用于Android。
import * as str from './index';
import axios from 'axios';
import { Permissions, Notifications } from 'expo';
export async function registerForPushNotificationsAsync(token) {
// Getting the status for this device
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
// Only ask if permissions have not already been determined, for iOS.
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Post new push token to backend for user
if(finalStatus !== 'granted'){
return;
}
// Get the push token that uniquely identifies this device
Notifications.getExpoPushTokenAsync()
// Post the success
.then(response => {
axios({
method: 'POST',
url: `${str.ROOT_URL}/account/push/`,
headers: {
Authorization: `Token ${token}`
},
data: {
"token": response,
"status": finalStatus
}
});
dispatch({ type: 'nothing' })
})
// Post the error
.catch(error => {
console.log(error.toString()) // THIS IS WHERE THE MESSAGE COMES
dispatch({ type: 'nothing' })
});
}