Local Notifications issue

Hello everyone,

Currently, I am using version 35.0.0 but local notifications don’t work. I import permissions and notifications as

import { Permissions, Notifications } from 'expo-permissions';

and then I obtain notifications as

async obtainNotificationPermission() {
      let permission = await Permissions.getAsync(Permissions.NOTIFICATIONS);
      if (permission.status !== 'granted') {
          permission = await Permissions.askAsync(Permissions.NOTIFICATIONS);
          if (permission.status !== 'granted') {
              Alert.alert('Permission not granted to show notifications');
          }
      }
      Notifications.addListener(this.handleNotification);
      return permission;
}

The error I am getting shown below.

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_expoPermissions.Permissions.getAsync')]
* components/ReservationComponent.js:61:41 in obtainNotificationPermission$
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:30 in invoke
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:28 in invoke
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:17 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:27 in callInvokeWithMethodAndArg
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:38 in enqueue
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:8 in <unknown>
* null:null in obtainNotificationPermission
* components/ReservationComponent.js:73:12 in presentLocalNotification$
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:30 in invoke
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:28 in invoke
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:17 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:27 in callInvokeWithMethodAndArg
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:38 in enqueue
- node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:8 in <unknown>
* null:null in presentLocalNotification
* components/ReservationComponent.js:51:44 in onPress
- node_modules/react-native/Libraries/Alert/Alert.js:158:17 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:414:4 in __invokeCallback
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:127:28 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:126:17 in invokeCallbackAndReturnFlushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

Any idea how to fix it?

Thanks,
Theo.

Hi

As per the Permissions and Notifications SDK 35 documentation, use this instead:

import * as Permissions from 'expo-permissions';
import { Notifications } from 'expo';
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.