firebase icon indicating copy to clipboard operation
firebase copied to clipboard

[messaging-core] Problems with requesting permissions on Android 33

Open PeterStaev opened this issue 2 years ago • 3 comments
trafficstars

I'm trying to migrate from the old firebase plugin to this one, and I'm getting some strange problem testing on a simulator with API 33. As soon as I call the request permissions, I do not get any prompts and I get a rejection. Here is a sample code:

export async function onTap() {
  try {
    const result = await MessagingCore.getInstance().requestPermission();
    console.log("RES", result);
  }
  catch (e) {
    console.error("ERROR", e);
  }
}

From what I see it is because of this: https://github.com/NativeScript/firebase/blob/889726640381cb4a0cdbe855f658ff3245a0eb3d/packages/firebase-messaging-core/index.android.ts#L314-L319

Does requesting permissions for notifications work only on physical devices?

Also why does this code reject while the iOS code resolves even if permission is denied but with the correct status code? Shouldn't this be changed to resolve(AuthorizationStatus.DENIED) for better cross platform interoperability? Right now I have to surround the request call with an empty try/catch to simulate similar behavior as on iOS.

PeterStaev avatar Dec 30 '22 15:12 PeterStaev

Just to clarify - although the permission seems declined I get a token, can register the device and receive notifications w/o any problem on the simulator.

PeterStaev avatar Dec 30 '22 16:12 PeterStaev

I may have missed an edge case but when testing on API 33 you will need to set the target and compile sdks to 33

triniwiz avatar Dec 30 '22 18:12 triniwiz

Changing compile and target SDK actually fixed the problem! Thanks @triniwiz ! I will leave this open in case the reject logic should also be changed so that it matches the iOS side.

PeterStaev avatar Jan 02 '23 08:01 PeterStaev