Notifications.getExpoPushTokenAsync无法在Stand Alone iOS上运行

问题描述 投票:0回答:1

我正在尝试我的expo / react-native项目向我的服务器发送推送通知。它适用于独立的Android,但不适用于独立的iPhone。

独立的iPhone应用程序永远不会发送令牌。

由于应用程序没有发送任何错误,我尝试删除:

if (finalStatus !== 'granted') { return; }

这也不起作用。

export async function registerForPushNotificationsAsync(token) {

  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;
  }

  // Stop here if the user did not grant permissions
  if (finalStatus !== 'granted') {
    return;
  }

  // Get the push token that uniquely identifies this device
  let expoToken = await Notifications.getExpoPushTokenAsync();

  // Post new push token to backend for user
  return axios({
    method: 'POST',
    url: `${str.ROOT_URL}/account/push/`,
    headers: {
      Authorization: `Token ${token}`
    },
    data: {
      "token": expoToken,
      "status": finalStatus
    }
  });

}

我希望令牌被发送到后端,但是在独立的iOS应用程序上没有发送任何内容。

如果您知道解决方法或之前遇到此问题,请通知我。谢谢!

ios react-native expo
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.