NativeScript / firebase

Modular Firebase 🔥 implementation for NativeScript. Supports both iOS & Android platforms for all Firebase services.
https://docs.nativescript.org/plugins/firebase-core.html
Apache License 2.0
56 stars 49 forks source link

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

Open PeterStaev opened 1 year ago

PeterStaev commented 1 year ago

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 commented 1 year ago

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.

triniwiz commented 1 year ago

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

PeterStaev commented 1 year ago

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.