#Events.PushNotification.TokenGenerated is never emitted

1 messages · Page 1 of 1 (latest)

nocturne oriole
#
import { On, Off, Events } from '#nativephp';
import { onMounted, onUnmounted } from 'vue';
 
const handleTokenGenerated = (payload) => {
    const { token } = payload;
    // Send token to your backend
    sendTokenToServer(token);
};
 
onMounted(() => {
    On(Events.PushNotification.TokenGenerated, handleTokenGenerated);
});
 
onUnmounted(() => {
    Off(Events.PushNotification.TokenGenerated, handleTokenGenerated);
});

The TokenGenerated event is never emitted, at least on Android (haven't tried iOS). The token itself does get generated, though.

@eternal bison @onyx ridge

trim phoenix
#

Can you confirm you're running v3, have the plugin installed and registered?

nocturne oriole
#

Yes. All newest versions of NativePHP and all plugins. await PushNotification.getToken() works correctly after the user has approved push notifications.

#

it's just that the event itself isn't emitted, so listening for it doesn't do anything...which is fairly inconvenient.

trim phoenix
#

Yeah, makes sense... going to look into this a bit

nocturne oriole
#

Thanks.

#

@trim phoenix while you're at it -- is it possible to also emit event on Permission Denied?

trim phoenix
#

Not positive but I think there might be a bug with the TokenGenerated event... I'll keep chasing it down

topaz citrus
#

Same problem for me. Please review whole package. I think there is more issues

eternal bison
#

Just tagged 1.0.5 with a fix for this, mind testing?

topaz citrus
#

Hmm can't find version 1.0.5, i did native install composer update, rm -rf vendors and composer update

nocturne oriole
#

Same, composer doesn't see 1.0.5

nocturne oriole
#

@eternal bison

eternal bison
#

checking one moment

eternal bison
#

can you try again now please?

trim phoenix
#

Worked for me

nocturne oriole
#
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires nativephp/mobile-secure-storage ^1.0, found nativephp/mobile-secure-storage[1.0.0] in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file.
#

I deleted my composer.lock, and now I'm getting this:

Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires nativephp/mobile-secure-storage, it could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
topaz citrus
#

same error for me

nocturne oriole
#

@eternal bison @trim phoenix

eternal bison
#

different error: Problem 1
- Root composer.json requires nativephp/mobile-secure-storage ^1.0, found nativephp/mobile-secure-storage[1.0.0] in the lock file but not in remote repositories, make sure you avoid updating this package to keep the one from the lock file.

nocturne oriole
#

@eternal bison correct. Something's gone wrong with that composer package. I've deleted the package-lock and the entire vendor folder, removed mobile-secure-storage from the composer.json and then ran composer update, and that went through.

Running composer require nativephp/mobile-secure-storage after that doesn't work:


In PackageDiscoveryTrait.php line 383:
                                                                            
  Could not find a matching version of package nativephp/mobile-secure-storage. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).
eternal bison
#

Simon is working on it now

onyx ridge
#

Sorry for the delay here folks, but this should be all sorted now. Please give it another go when you get the chance @nocturne oriole @topaz citrus

topaz citrus
#

I successfully installed 1.0.5, and I think the event is emitted twice. After I enroll permission dialog and accept it i am getting two events. Can you confirm this? @nocturne oriole

nocturne oriole
#

@eternal bison @onyx ridge @topaz citrus

On Windows + Android this is completely broken:

1) TokenGenerated event gets emitted as soon as the pop up with "Accept" and "Decline" options is shown, without the user clicking either option. I do get a token in this case, but that token is useless because of the following -- as soon as that pop up is shown, Android sets the permission status to "denied", and then if user either just exist the modal without choosing anything, or clicks denied, the status is correct - "denied" - which means we can't use the token.

2) When the TokenGenerated event is triggered if I immediately call await PushNotifications.checkPermission(); that never resolves, the code just gets "stuck". The workaround for this is handling TokenGenerated event with a delay. I've tried 1s delay and that worked. However...

3) The biggest issue -- after the user actually clicks Accept in the pop up, the token generated event is not triggered again.


I assume the initially generated token can be used after the user clicks on "Accept", however we never get that information. Currently the only way around this is polling for permission change, and once it changes from "denied" to anything else, that is when we can send token to our backend. However this is very impractical since the user could click on "deny", which will leave the push permission in the "denied" state, so we'd either just continue polling forever, or have a timeout on the polling function which again leaves room for edge cases where the user clicks "accept" after the timeout's already expired.

#

If we could either get TokenGenerated after the user clicks Accept, or have a new event PushPermissionStatusChanged, that would be great.

clear tartan
# onyx ridge Sorry for the delay here folks, but this should be all sorted now. Please give i...

Hi @onyx ridge I just tried it and still facing the same error

composer require nativephp/mobile-secure-storage

In PackageDiscoveryTrait.php line 383:
                                                                                                                                                                                    
  Could not find a matching version of package nativephp/mobile-secure-storage. Check the package spelling, your version constraint and that the package is available in a stabili  
  ty which matches your minimum-stability (stable).

Is there some command we are meant to run first?