schedule notification error

[Unhandled promise rejection: Error: Failed to schedule notification.]

  • node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:103:50 in promiseMethodWrapper
  • node_modules@unimodules\react-native-adapter\build\NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
  • node_modules\expo-notifications\build\scheduleNotificationAsync.js:4:15 in scheduleNotificationAsync
  • node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
  • node_modules\regenerator-runtime\runtime.js:293:29 in invoke
  • node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
  • node_modules\regenerator-runtime\runtime.js:154:27 in invoke
  • node_modules\regenerator-runtime\runtime.js:189:16 in PromiseImpl$argument_0
  • node_modules\react-native\node_modules\promise\setimmediate\core.js:45:6 in tryCallTwo
  • node_modules\react-native\node_modules\promise\setimmediate\core.js:200:22 in doResolve
  • node_modules\react-native\node_modules\promise\setimmediate\core.js:66:11 in Promise
  • node_modules\regenerator-runtime\runtime.js:188:15 in callInvokeWithMethodAndArg
  • node_modules\regenerator-runtime\runtime.js:211:38 in enqueue
  • node_modules\regenerator-runtime\runtime.js:238:8 in exports.async
  • node_modules\react-native\Libraries\Pressability\Pressability.js:691:17 in _performTransitionSideEffects
  • node_modules\react-native\Libraries\Pressability\Pressability.js:628:6 in _receiveSignal
  • node_modules\react-native\Libraries\Pressability\Pressability.js:524:8 in responderEventHandlers.onResponderRelease
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:500:2 in invokeGuardedCallbackAndCatchFirstError
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:597:41 in executeDispatch
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:621:19 in executeDispatchesInOrder
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2521:28 in executeDispatchesAndRelease
  • [native code]:null in forEach
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:836:4 in forEachAccumulated
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2546:20 in runEventsInBatch
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2702:18 in runExtractedPluginEventsInBatch
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2639:35 in batchedUpdates$argument_0
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17712:13 in batchedUpdates$1
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2492:29 in batchedUpdates
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2638:16 in _receiveRootNodeIDEvent
  • node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2767:27 in receiveTouches
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue

import { StatusBar } from “expo-status-bar”;

import React, { useEffect } from “react”;

import { StyleSheet, Button, View } from “react-native”;

import * as Notifications from “expo-notifications”;

import * as Permissions from “expo-permissions”;

export default function App() {

useEffect(() => {

Permissions.getAsync(Permissions.NOTIFICATIONS)

  .then((statusObj) => {

    if (statusObj.status !== "granted") {

      return Permissions.askAsync(Permissions.NOTIFICATIONS);

    }

    return statusObj;

  })

  .then((statusObj) => {

    if (statusObj.status !== "granted") {

      return;

    }

  });

}, );

const triggerNotificationHandler = () => {

Notifications.scheduleNotificationAsync({

  content: {

    title: "My first local notification",

    body: "This is the first local notification we are sending!",

  },

  trigger: {

    seconds: 10,

  },

});

};

return (

<View style={styles.container}>

  <Button

    title="Trigger Notification"

    onPress={triggerNotificationHandler}

  />

  <StatusBar style="auto" />

</View>

);

}

const styles = StyleSheet.create({

container: {

flex: 1,

backgroundColor: "#fff",

alignItems: "center",

justifyContent: "center",

},

});

This works fine in the android emulator but it does not work in android mobile phone when I was running through expo app in the play store by scanning QR code of the project. I want to know why??

Hey @ravindujayasekara, please make sure your code is formatted and readable when making a post. From a quick glance, it looks like your missing async in your handler.

Cheers,
Adam

const triggerNotificationHandler = async () => {
await Notifications.scheduleNotificationAsync({
content: {
title: “My first local notification”,
body: “This is the first local notification we are sending!”,
data: { mySpecialData: “Some text” },
},
trigger: {
seconds: 10,
},
});
};

I really need a solution for this sir. It works fine for the emulator. I tried that in my android mobile phone but it gives me that previous error. I tried everything that I could.

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