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

Pinpoint Notifications always use APNs Sandbox channel #4875

Closed
2 of 14 tasks
Niklas-Sommer opened this issue May 12, 2024 · 11 comments
Closed
2 of 14 tasks

Pinpoint Notifications always use APNs Sandbox channel #4875

Niklas-Sommer opened this issue May 12, 2024 · 11 comments
Assignees
Labels
Investigating Issues that are assigned and are being looked into pending-response Issue is pending response from the issue requestor push notifications

Comments

@Niklas-Sommer
Copy link

Description

I am working on a flutter app that uses amplify and use cognito for user authentication and pinpoint to send push notifications. I am calling a lambda function to send my push notifications. This lambda function looks up all the endpoints registered to one user and sends the push notification to all of them. Everything works perfectly fine when launching in debug mode but when I launch my app in release mode the messages are not delivered. When looking through the cloud watch logs of my lambda function I can see that amplify correctly registers the endpoint as APNs Sandbox for the debug build and as APNs for the release build. Since they seem to be correctly registered I tried sending a test message using the AWS pinpoint console and found out that alltough the endpoint is registered as APNs the messages only get delivered when sent to the APNs Sandbox channel in both debug and release build. I created another bare bones test project and was able to reproduce this issue.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. Create new flutter app
  2. Init amplify with auth and notifications according to the guide on the website
  3. Configure amplify in the flutter app according to the guide
  4. Retrieve the device token
  5. Launch the app in release mode and send a test message using amazon pinpoint on APNs channel and on APNs Sandbox channel to the device token. Only APNs Sandbox will work.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.19.6

Amplify Flutter Version

^1.7.0

Deployment Method

Amplify CLI

Schema

No response

@NikaHsn
Copy link
Contributor

NikaHsn commented May 13, 2024

@Niklas-Sommer thanks for taking the time to raise this issue. Amplify will decide the appropriate channel based on the application's compiled environment and if it is running on debug mode it registers the endpoint as APNs Sandbox . While we investigate, could you please verify whether the release app is running in debug mode using zDebugMode similar to the code snippet below:

if (zDebugMode) {
  print('running on debug mode');
}

@NikaHsn NikaHsn added pending-response Issue is pending response from the issue requestor push notifications Investigating Issues that are assigned and are being looked into labels May 13, 2024
@Niklas-Sommer Niklas-Sommer reopened this May 14, 2024
@Niklas-Sommer
Copy link
Author

I did test that and it is indeed running in release mode. As stated above it even gets registered in pinpoint as an APNs endpoint but I still only receive push notifications when I send it to the APNs Sandbox channel. That's the error I get when sending a test message with the pinpoint console to the the APNs channel:

Request Id 68 : [<DEVICE_TOKEN>: PERMANENT_FAILURE {"errorMessage":"Unregistered or expired token","channelType":"APNS","pushProviderStatusCode":"400","pushProviderError":"BadDeviceToken","pushProviderResponse":"{"reason":"BadDeviceToken"}"}]

@NikaHsn
Copy link
Contributor

NikaHsn commented May 15, 2024

@Niklas-Sommer thank you for providing these details. we will look into this issue and get back to you with any updates.

@NikaHsn NikaHsn removed the pending-response Issue is pending response from the issue requestor label May 16, 2024
@NikaHsn
Copy link
Contributor

NikaHsn commented May 16, 2024

@Niklas-Sommer when running flutter run command do you use any command line options such as --dart-define to set environment valriables?

@NikaHsn NikaHsn added pending-response Issue is pending response from the issue requestor and removed Investigating Issues that are assigned and are being looked into labels May 16, 2024
@Niklas-Sommer
Copy link
Author

I am launching my flutter project from VS Code in release mode so I didn't specify any. Not sure which arguments vs code passes when launching.

@Niklas-Sommer
Copy link
Author

Just tried running from the command line with

flutter run --release

Still does not work

@NikaHsn
Copy link
Contributor

NikaHsn commented May 18, 2024

@Niklas-Sommer sending notifications directly through the Pinpoint console to both APNS and APNS_SANDBOX channels with tokens and only APNS_SANDBOX is successfully delivered indicates that the device token received from APNs is for the sandbox environment.
Would you please verify that the APNS SSL certificate is for Sandbox & Production?
image (5)
If the certificate is for Sandbox only then you may need to generate a certificate for Sandbox and Production and update the Pinpoint project to use the new certificate.

@Niklas-Sommer
Copy link
Author

I am not quite sure where on apple developer you navigated to find what is shown on your screenshot but I checked
AppleDeveloper->Identifiers->MYAPP->Push Notifications->Edit
and can see that I have a production SSL certificate. No development certificate.

Screenshot 2024-05-18 at 08 08 16

I also checked in my pinpoint project and that looks like this:

Screenshot 2024-05-18 at 08 12 30

Were you not able to reproduce this issue by just creating a basic flutter project with amplify according to the documentation?

@Equartey Equartey removed the pending-response Issue is pending response from the issue requestor label May 20, 2024
@Equartey
Copy link
Contributor

Hi @Niklas-Sommer, I've been able to reproduce this on a fresh Amplify Flutter app.

I'm still investigating the root cause, but wanted to update you in the meantime.

I'll provide more information when I have it.

@Equartey Equartey added the Investigating Issues that are assigned and are being looked into label May 21, 2024
@Equartey Equartey self-assigned this May 21, 2024
@Equartey
Copy link
Contributor

Hi @Niklas-Sommer, it appears running the app with the release flag is not sufficient for iOS to setup the correct production environment. I was able to successfully receive a APNs (non-sandbox) push notification through both of these methods:

  • Build the Flutter iOS via .ipa,
    • Using this command flutter build ipa --release --export-method ad-hoc
    • Plug in your physical device and drag & drop the .ipa file onto the device
    • Here is a relevant stack overflow
  • Test App via TestFlight

For both scenarios ensure you don't have a pre-existing version of the app already installed. And ensure you have a method of retrieving the device id.

Note: when the app is built this way APNs Sandbox push notifications will throw a similar error to what you were getting before.

Let us know if this resolves the issue for you or if you have additional questions.

@Equartey Equartey added the pending-response Issue is pending response from the issue requestor label May 21, 2024
@Niklas-Sommer
Copy link
Author

Niklas-Sommer commented May 21, 2024

Well that was a quick fix :D Thanks a lot for the help! It would be great if this was mentioned in the documentation though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigating Issues that are assigned and are being looked into pending-response Issue is pending response from the issue requestor push notifications
Projects
None yet
Development

No branches or pull requests

3 participants