wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

TypeError: _reactNativeNotifications.Notifications.requestPermissions is not a function #501

Closed puremana closed 4 years ago

puremana commented 4 years ago

Just trying to follow https://wix.github.io/react-native-notifications/docs/subscription

and I get TypeError: _reactNativeNotifications.Notifications.requestPermissions is not a function when I use Notifications.requestPermissions();

I'm receiving the device token just fine.

import React from 'react';
import { StatusBar } from 'react-native';
import { Notifications } from 'react-native-notifications';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();

import Home from './screens/Home';
import Schedule from './screens/Schedule';

import firebase from '@react-native-firebase/app';
console.log(firebase.app().name);

class App extends React.Component {
  constructor(props) {
    super(props);
    Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
        // TODO: Send the token to my server so it could send back push notifications...
        console.log("Device Token Received", event.deviceToken);
    });
    Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
        console.error(event);
    });

    Notifications.requestPermissions();

This is using react-native run-android on a Samsung J5

Thanks!

trinhak commented 4 years ago

you should add Notifications.registerRemoteNotifications(); before registerRemoteNotificationsRegistered() it's ok for me and the new libr not use Notifications.requestPermissions(); you should change Notifications.ios.registerRemoteNotifications() (only ios) you should check platform;

puremana commented 4 years ago

you should add Notifications.registerRemoteNotifications(); before registerRemoteNotificationsRegistered() it's ok for me and the new libr not use Notifications.requestPermissions(); you should change Notifications.ios.registerRemoteNotifications() (only ios) you should check platform;

So you mean I should do this?

import React from 'react';
import { StatusBar, Platform } from 'react-native';
import { Notifications } from 'react-native-notifications';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();

import Home from './screens/Home';
import Schedule from './screens/Schedule';

import firebase from '@react-native-firebase/app';
console.log(firebase.app().name);

class App extends React.Component {
  constructor(props) {
    super(props);

    if (Platform.OS === 'ios') {
      Notifications.ios.registerRemoteNotifications();
    }

    Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
      // TODO: Send the token to my server so it could send back push notifications...
      console.log("Device Token Received", event.deviceToken);
    });
    Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
        console.error(event);
    });
trinhak commented 4 years ago

you should add Notifications.registerRemoteNotifications(); before registerRemoteNotificationsRegistered() it's ok for me and the new libr not use Notifications.requestPermissions(); you should change Notifications.ios.registerRemoteNotifications() (only ios) you should check platform;

So you mean I should do this?

import React from 'react';
import { StatusBar, Platform } from 'react-native';
import { Notifications } from 'react-native-notifications';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();

import Home from './screens/Home';
import Schedule from './screens/Schedule';

import firebase from '@react-native-firebase/app';
console.log(firebase.app().name);

class App extends React.Component {
  constructor(props) {
    super(props);

    if (Platform.OS === 'ios') {
      Notifications.ios.registerRemoteNotifications();
    }

    Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
      // TODO: Send the token to my server so it could send back push notifications...
      console.log("Device Token Received", event.deviceToken);
    });
    Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
        console.error(event);
    });

yes. and you add Notifications.registerRemoteNotifications() before registerRemoteNotificationsRegistered()

puremana commented 4 years ago

So this?

    Notifications.registerRemoteNotifications();

    if (Platform.OS === 'ios') {
      Notifications.ios.registerRemoteNotifications();
    }

That doesn't make much sense to me as I thought on android we don't need to request permission as it is automatically granted. So what would be the point of Notifications.registerRemoteNotifications(); in this case?

trinhak commented 4 years ago

So this?

    Notifications.registerRemoteNotifications();

    if (Platform.OS === 'ios') {
      Notifications.ios.registerRemoteNotifications();
    }

That doesn't make much sense to me as I thought on android we don't need to request permission as it is automatically granted. So what would be the point of Notifications.registerRemoteNotifications(); in this case?

ok you needless add it

puremana commented 4 years ago

ok you needless add it

Sorry, I'm having a bit of trouble understanding. What do you mean by that?