aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 247 forks source link

Android version can't setup/use AmplifyPushNotificationsPinpoint() plugin #5384

Open marcuscheung-carbonlinking opened 2 months ago

marcuscheung-carbonlinking commented 2 months ago

Description

ios version is ok, android version work before, my flutter version: 3.24.0.

this my amplify configure method:

Future<void> _configureAmplify() async {
  try {
    final authPlugin = AmplifyAuthCognito();
    final notificationsPlugin = AmplifyPushNotificationsPinpoint();
    notificationsPlugin
        .onNotificationReceivedInBackground(myAsyncNotificationReceivedHandler);

    await Amplify.addPlugins([
      authPlugin,
      notificationsPlugin,
      AmplifyAPI(modelProvider: ModelProvider.instance),
      AmplifyStorageS3(),
    ]);
    await Amplify.configure(amplifyconfig);
  } on Exception catch (e) {
    safePrint('An error occurred configuring Amplify: $e');
  }
}

this the error message:

 An error occurred configuring Amplify: PushNotificationException {
 "message": "Error occurred awaiting for device token to register device with Pinpoint",
 "recoverySuggestion": "Please review the underlying exception",
"underlyingException": "UnknownException {\n  \"message\": \"Forbidden from accessing the Pinpoint resource.\",\n  \"recoverySuggestion\": \"Please ensure Analytics is properly configured in your amplifyconfiguration.dart file and that unauthenticated guest access is allowed or an authorized user is signed in.\",\n  \"underlyingException\": \"ForbiddenException {\\n}\"\n}"
}

my amplify package version: amplify_flutter: ^1.8.0 amplify_api: ^1.8.0 amplify_auth_cognito: ^1.8.0 amplify_core: ^1.8.0 amplify_storage_s3: ^1.8.0 amplify_push_notifications_pinpoint: ^1.8.0

Categories

Steps to Reproduce

launch the flutter project with android device and use AmplifyPushNotificationsPinpoint plugin

Screenshots

No response

Platforms

Flutter Version

3.24.0

Amplify Flutter Version

1.8.0

Deployment Method

Amplify CLI (Gen 1)

Schema

No response

Jordan-Nelson commented 2 months ago

Hello @marcuscheung-carbonlinking - Do you know what changes were made between the time when this was working to when it stopped working? Did you upgrade flutter, are you testing on a new device, were there code changes?

marcuscheung-carbonlinking commented 2 months ago

i just have one android device for testing. i did upgraded flutter version from 3.19.6 to 3.24.0, but i also try to downgrade/install flutter again. i'm not sure since when, but we have develop branch for stable version of app, that can't init pinpoint plugin too.

Jordan-Nelson commented 2 months ago

Is the user authenticated when this error occurs? Have you configured unauthenticated guest access for pinpoint?

marcuscheung-carbonlinking commented 2 months ago

i notice the error message has one more line: INFO | EndpointInfoStoreManager | No EndpointId found, generating a new one. An error occurred configuring Amplify: PushNotificationException { "message": "Error occurred awaiting for device token to register device with Pinpoint", "recoverySuggestion": "Please review the underlying exception", "underlyingException": "UnknownException {\n \"message\": \"Forbidden from accessing the Pinpoint resource.\",\n \"recoverySuggestion\": \"Please ensure Analytics is properly configured in your amplifyconfiguration.dart file and that unauthenticated guest access is allowed or an authorized user is signed in.\",\n \"underlyingException\": \"ForbiddenException {\n}\"\n}" }

marcuscheung-carbonlinking commented 2 months ago

Is the user authenticated when this error occurs? Have you configured unauthenticated guest access for pinpoint?

backend setting?

Jordan-Nelson commented 2 months ago

Yes, this would be a setting that would have been enabled when setting up the backend.

marcuscheung-carbonlinking commented 2 months ago

weird thing, last friday i try to setup another amplify-flutter project for deeper explorer amplify&pinpoint, same setup is work. and after that, my previous project also work now... since i explorer amplify in my personal computer, it should not related to cache issue, configuration issue or account issue. not understand why just work again.

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

marcuscheung-carbonlinking commented 2 months ago

but test on real device still have that error: /flutter (16447): An error occurred configuring Amplify: PushNotificationException { I/flutter (16447): "message": "Error occurred awaiting for device token to register device with Pinpoint", I/flutter (16447): "recoverySuggestion": "Please review the underlying exception", I/flutter (16447): "underlyingException": "UnknownException {\n \"message\": \"Forbidden from accessing the Pinpoint resource.\",\n \"recoverySuggestion\": \"Please ensure Analytics is properly configured in your amplifyconfiguration.dart file and that unauthenticated guest access is allowed or an authorized user is signed in.\",\n \"underlyingException\": \"ForbiddenException {\n}\"\n}"

Jordan-Nelson commented 2 months ago

@marcuscheung-carbonlinking - That error would indicate that there currently is no user logged in and that your pinpoint backend is not setup to allow unauthenticated users. Here are the steps to setup pinpoint with the Gen 1 CLI and enable unauthenticated access: https://docs.amplify.aws/gen1/flutter/build-a-backend/push-notifications/set-up-push-notifications/#set-up-backend-resources

marcuscheung-carbonlinking commented 2 months ago

@marcuscheung-carbonlinking - That error would indicate that there currently is no user logged in and that your pinpoint backend is not setup to allow unauthenticated users. Here are the steps to setup pinpoint with the Gen 1 CLI and enable unauthenticated access: https://docs.amplify.aws/gen1/flutter/build-a-backend/push-notifications/set-up-push-notifications/#set-up-backend-resources

i try to install android version flutter app (same code, same build) on sumsung A12 & sony XQ-DC72.A12 works. but XQ-DC72 can't. both android 14(update to date).

if we upgrade to amplify 2.x, will it fix my issue?

tyllark commented 2 months ago

Hello @marcuscheung-carbonlinking, can you please confirm that you have both authenticated and guest access enabled in Cognito. AWS Console -> Cognito -> Identity pools -> Identity pool name -> User access

Afterwards can to please confirm that the IAM policies for both are configured per our documentation.