evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 681 forks source link

FCM Object functions not working while sending push notifications #1035

Open meghachetan opened 5 years ago

meghachetan commented 5 years ago

I am using this module for push notifications in my react-native app using firebase cloud messaging service. I follow up this module example simple-fcm-client but i had implemented code for it but it is not working.

Problem: when i starts my app i check out with console that i have the correct FCM object with me but found that the function FCM.createNotificationChannel not working. Means the code doesn't works out from the FCM.createNotificationChannel function even if any normal console line is written next to this function block and also no error comes from the step the function of notification channel is called.

Expected: Please help me for properly executing the push notifications implementation in my react-native app using fcm with fcm registered token for the android ios device.

RN(React Native) Version 0.55.2 react-native-fcm Version 16.2.0 Device using Android 7 device Android CompileSDKVersion = 26 Android TargetSDKVersion = 26 AndroidMinSDKVersion = 16 Java Version 8 Windows 7 App running either in foreground or background but the FCM Object functions usage neither works out nor gives any error.

===========build.gradle file================== buildToolsVersion = "26.0.3" minSdkVersion = 16 compileSdkVersion = 26 targetSdkVersion = 26 supportLibVersion = "26.0.0-alpha1"

=================React Native Code=============== import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType, NotificationActionType, NotificationActionOption, NotificationCategoryOption} from "react-native-fcm";

` async componentDidMount() {

registerAppListener();
console.warn(FCMEvent);  // complete object is printed in console output
console.warn(FCM);  // complete object is printed in console output

FCM.createNotificationChannel({  // Not working No result
  id: 'aa',
  name: 'aa',
  description: 'used for example',
  priority: 'max'
});

FCM.getInitialNotification().then(notif => {   // Not working No result
  this.setState({
    initNotif: notif
  });
  if (notif && notif.targetScreen === "detail") {
    setTimeout(() => {
      this.props.navigation.navigate("Detail");
    }, 500);
  }
});

try {
  let result = await FCM.requestPermissions();   // Not working No result
} catch (e) {
  console.warn(e);
}

FCM.getFCMToken().then(token => {   // Not working No result
  console.warn("TOKEN (getFCMToken)", token);
  this.setState({ token: token || "" });
});

if (Platform.OS === "ios") {   
  FCM.getAPNSToken().then(token => {    // Not working No result
    console.warn("APNS TOKEN (getFCMToken)", token);
  });
}

}`

christianchown commented 5 years ago

Hard to tell what's going on without more detail. I have similar code working fine. try adding

try {
  await FCM.requestPermissions();
} catch (error) {
  console.log(error);
  // do something here
}

before you createNotificationChannel. When you say "Not working No result" what do you mean? For example, createNotificationChannel does not return anything. What happens if you step over/into the code in a debugger?