Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Notifications.getExpoPushTokenAsync() - Error Notification registration failed: "Push Notifications" #19720

Closed
seb-glanum opened this issue Oct 27, 2022 · 8 comments
Labels

Comments

@seb-glanum
Copy link

seb-glanum commented Oct 27, 2022

Summary

Since a little time, I no longer get the Expo Token in all my apps in production. I revoke my provisioning profile with the expo command line for a new one, I have the Push Notification key in my Apple Developer Credentials but it's still not working anymore.
No issues when i'm using Expo Go app to get the push token.

I put try/catch function to see why this not working on my build app. Here's a screenshot with the error message.

Error Notification registration failed: "Push Notifications" capability hasn't been added to the app in current environment : No valid 'aps-environment' entitlement string found for application

I tried everything from the Expo documentation troubleshooting but nothing is working.

I'm using expo-cli to build my app (classic system). Expo SDK 45. Only on iOS.
IMG_6814

What platform(s) does this occur on?

iOS

Environment

expo-env-info 1.0.5 environment info:
System:
OS: macOS 12.6
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.13.2 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.1.2 - /usr/local/bin/npm
Watchman: 2021.09.06.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8609683
Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
npmPackages:
expo: 45.0.6 => 45.0.6
react: 17.0.2 => 17.0.2
react-dom: 17.0.2 => 17.0.2
react-native: 0.68.2 => 0.68.2
react-native-web: 0.17.7 => 0.17.7
npmGlobalPackages:
eas-cli: 0.54.1
expo-cli: 6.0.6
Expo Workflow: managed

Minimal reproducible example

const registerForPushNotificationsAsync = async () => {
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") {
console.log("�[" + 32 + "m" + "Failed to get push token for push notification! : " + "�[0m")
return
}
try {
const token = (await Notifications.getExpoPushTokenAsync()).data
console.log(token)
} catch (error) {
Alert.alert("error", error.toString())
}
} else {
console.log("Must use physical device for Push Notifications")
}

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

}

@seb-glanum seb-glanum added the needs validation Issue needs to be validated label Oct 27, 2022
@bayramn
Copy link

bayramn commented Nov 4, 2022

I started have this exact warning all of sudden. The warning still there even if I remove Notifications.getExpoPushTokenAsync().

@seb-glanum
Copy link
Author

I started have this exact warning all of sudden. The warning still there even if I remove Notifications.getExpoPushTokenAsync().

I removed this method if I still get the warning, finally the warning doesn't show anymore.

Maybe you have the same issue as me or you have something else which can break Notifications.

Anyway, I am in contact with the Expo team (via secure@expo.io) to solve this issue. They're debugging the Expo Core Code.

I make a search for this error and in forums, it corresponds to => No valid 'aps-environment' entitlement string found for application.
https://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store
but when you see the answers, I need to enable a parameter in the XCode project, but I am in Expo Managed Project. I can’t do anything in my side since there is no XCode Project in Managed Projects.

@bayramn
Copy link

bayramn commented Nov 9, 2022

I don't know what is happening, this started all of sudden and my notifications stopped working.

@seb-glanum
Copy link
Author

I have resolved this issue with building my app with EAS but I have some issues with it.
And yes ! @bayramn, I have apps in the App Store production which the notifications were working perfect and suddenly it not working anymore without I push a new version of my apps.

@bayramn
Copy link

bayramn commented Nov 9, 2022

I resolved the issue. Warning disappeared and Notifications working now. It was from app.json plugins that was messing with Notifications aps-environment plugins of onesignal library. According to onesignal-expo-plugin docs, if you have extra plugins that modify capabilities in your app.json on top of Notifications capabilities, then expo randomly selects one capability and doesn't setup the Notifications capability.

In my case I had a expo-screen-orientation plugin capability and after removing it, the issue got resolved,

  "plugins": [ 
      "@lyrahealth-inc/react-native-orientation-plugin",
       "plugins": [ 
        [
          "expo-screen-orientation",                           <-- removed this plugin whole array.
          {
          "initialOrientation": "ALL"
          }
        ],
        [
            "onesignal-expo-plugin",
            {
              "mode": "development"
            }
        ],  
  ],

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2023

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Feb 7, 2023
@github-actions
Copy link
Contributor

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

@smn-snkl
Copy link

In case someone else runs into this, we found that the OneSignal Expo Plugin docs recommend to put the plugin first in the array: https://github.com/OneSignal/onesignal-expo-plugin/blob/main/README.md#plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants