HMS-Core / hms-react-native-plugin

This repo contains all of React-Native HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
235 stars 67 forks source link

[react-native-hms-push] HmsPushInstanceId.getToken error #275

Open JACA26 opened 1 year ago

JACA26 commented 1 year ago

Description I installed the react-native-hms-push package and configured all ok, run the app on emulator o phisical device all its ok but when i generate the apk for test i have this error when i get the token of device

Screenshots If applicable, add screenshots to help explain your issue

Error image

The code to obtain the token is this: ` export async function getTokenFCM() { // Register the device with FCM const isHuawei = await validateHuaweiDevice(); let token = ''; if (Platform.OS !== 'ios') { if (!isHuawei) { await messaging().registerDeviceForRemoteMessages(); } }

// Get the token

if (Platform.OS === 'ios') { token = await messaging().getAPNSToken(); } else { if (isHuawei) { token = await HmsPushInstanceId.getToken(); token = token['result'] && parseInt(token['resultCode']) === 0 ? token['result'] : ''; } else { token = await messaging().getToken(); } }

console.log('TOKEN OBTAINED', token);

return token; } `

Environment

Other the validateHuaweiDevice function return a Boolean with the @hmscore/react-native-hms-availability service

nkostop commented 1 year ago

You need to change this line token = await HmsPushInstanceId.getToken(); With this: token = await HmsPushInstanceId.getToken('');

Essentially you need an empty string argument for the getToken method.

MrutyunjayaB commented 1 month ago

In case of iOS, i am getting HmsPushInstanceId as null itself. How can i fix it