English 中文(简体)
Receiving error while reqeusting notification permission on expo app
原标题:

I Have a simple code that asks for notifications permission that worked in the past, but suddently,It s giving me this error:

"Error: Encountered an exception while calling native method: Exception occurred while executing exported method requestPermissionsAsync on module ExpoNotificationPermissionsModule: String resource ID #0xffffffff"

Code:

    if (isDevice) {
        const { status: existingStatus } = await Notifications.getPermissionsAsync();
        let finalStatus = existingStatus;
        if (existingStatus !== "granted") {
            const { status } = await Notifications.requestPermissionsAsync();
            finalStatus = status;
        }
        if (finalStatus !== "granted") {
            Alert.alert("Falha ao obter permissão para notificações push!", "É necessário permitir o envio de notificações push para o aplicativo funcionar corretamente.");
            return "";
        }
        token = (await Notifications.getExpoPushTokenAsync()).data;
    } else {
        alert("Para gerar o token de notificação você precisa estar em um dispositivo físico!");
    }
最佳回答

Same story here, it was working till recently. Didnt even look to part of code responsible for registering for notifications. Since it s not related to codebase look for issue source elswhere. My phone updated to new Os version recently, so i have uninstalled expo and clear all the app data/storage. Also i ve updated expo-cli and started with untoutched codebase with the same device. I got prompted for permission for notifications and this part of code went trough. Although secure storage is not working now :-). Anyway that s a starting point for you.

问题回答

On Android 13, app users must opt-in to receive notifications via a permissions prompt automatically triggered by the operating system. This prompt will not appear until at least one notification channel is created. The setNotificationChannelAsync must be called before getDevicePushTokenAsync or getExpoPushTokenAsync to obtain a push token. You can read more about the new notification permission behavior for Android 13 in the official documentation.

async function registerForPushNotificationsAsync() {
  let token;

  if (Platform.OS ===  android ) {
    await Notifications.setNotificationChannelAsync( default , {
      name:  default ,
      importance: Notifications.AndroidImportance.MAX,
      vibrationPattern: [0, 250, 250, 250],
      lightColor:  #FF231F7C ,
    });
  }

  if (Device.isDevice) {
    const { status: existingStatus } = await Notifications.getPermissionsAsync();
    let finalStatus = existingStatus;
    if (existingStatus !==  granted ) {
      const { status } = await Notifications.requestPermissionsAsync();
      finalStatus = status;
    }
    if (finalStatus !==  granted ) {
      alert( Failed to get push token for push notification! );
      return;
    }
    token = (await Notifications.getExpoPushTokenAsync()).data;
    console.log(token);
  } else {
    alert( Must use physical device for Push Notifications );
  }

  return token;
}

Clear storage data and Uninstall expo go app. Download it again and app should be prompting permission.

Irfan Muhammad s solution worked for me,

I also moved the registerForPushNotificationsAsync function to the top of my App.js file before I uninstalled expo go and reinstalled it.

Not sure if moving the function made a difference but it s what I did. The prompt then immediately came up.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签