how to use "export interface CalendarNotificationTrigger"

@charliecruzan Thank you for the quick reply! Yes, I’ve been reading this push notification documentation for the past few months; after experimenting I concluded that I don’t need all of the push notification code if I am only doing local notifications. Maybe I am wrong?

Yes, that is correct. I have this snippet starting with registerForPushNotificationsAsync from the documentation you cited but nothing happens after I build and send to test flight on ios.

When I install my app (after building the ios version and sending to Test Flight and installing via test flight on my device) then I don’t see a request to “Allow” notifications. Even though during development I am seeing local notifications (only when app is in foreground) based on current date.

I just pushed an update on the Apple Store and when I updated my expo app on my personal ios device it prompted me “do you want this app to send notifications?” So, this is a good sign. I will follow up tomorrow because the way my app is coded I should receive a notification at 3 am tomorrow morning. Hoping for the best! :crossed_fingers:t2:

unfortunately the app did not display any notification.
good sign that at least it asked for permission to display notifications. I think that’s progress…

Has anyone had any luck with local notifications? Calendar-based notifications?

When you ask for permissions, does it return granted? I know that local notifications work, I use them myself and we have the example on the docs page using it. Happy to try and help you figure this out but I’ll need a minimal reproducible demo of your issue so I can help debug :smile:

hey there @charliecruzan apologies for late reply. Thank you for your kind consideration. When you say, “minimal reproducible demo,” does that mean I should strip everything except the page where notifications code is? I have a public github of this project here: GitHub - vital-tech-results/react-native-app-ekadasi: react native app based on expo CLI

The notifications code is on Screens/HomeScreen.js

let me know and I will be happy to push a fresh repo with minimal code to reproduce the issue.

:face_with_head_bandage:

hey there @charliecruzan I got notifications to work when not in foreground by looking carefully at the documentation in development when using expo app on ios.

I am using sDK 39

notifications also work when app is in foreground

this is what I wanted so I made a fresh build, pushed to Apple and used test flight on my device to install the test build. when launching my app for the first time I get a dialogue requesting to allow my app to send notifications; and when I open settings > notifications I see my app listed and activated.

However, notifications do not work; app was not launched. How can I test if notifications work when app is not open at all (not in foreground AND not open)? In order to test I need to have the expo app installed and running and connecting to my app, correct?

I would be grateful for any help. I don’t know what else to do.

Could you be more specific?

  • Do notifications show up in the device at all? If not, check the push receipt.
  • Do notifications show up, but then pressing them doesn’t open the app? I haven’t seen this happen before so please provide a way for me to reproduce that
  • Do notifications show up, and then tapping them opens the app, but then your listeners aren’t triggered? You’ve probably misconfigured something so I would double check your code with the docs

You should be able to test local notifications on a simulator with a simulator build expo build:ios -t simulator, if not then you will need to test via testflight

Hey there thanks for the quick reply.

My situation is this:

  • Do notifications show up in the device at all? If not, check the push receipt.”

But how would I check the push receipt? will I check it on my device somehow?

I recommend reading through all push notification docs first- Push Notifications Overview - Expo Documentation

I thought that since I am using local notifications I didn’t need to send notifications to an external server. I guess I need this step. But why has it been working during development even though I never implemented anything in the docs here: Sending Notifications with Expo's Push API - Expo Documentation

After looking at the docs in the link you provided, I managed to implement the push receipt in my code and console.log a receipt. Now I suppose I could write the response to a log file. But I can’t figure out how to access content of scheduleNotificationAsync; this content would be sent in the request for a receipt instead of hardcoding a message in the body of a json request as seen in the link you provided.

I also see there is a handleError method on the setNotificationHandler; I was thinking that I could put the push receipts code there.

This is what I have for push receipts (but not sure how to input the body: JSON.stringify from my scheduled Notification body:

// first send a push notification with body text
async function getNotifsFromApiAsync() {
  return await fetch('https://exp.host/--/api/v2/push/send', {
    method: 'POST',
    headers: {
      Host: 'exp.host',
      Accept: 'application/json',
      'Accept-Encoding': 'gzip, deflate',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      "to": "ExponentPushToken[in3MwyHdqFTopctcsNwBdI]",
      "title": "hello from ekad app",
      "body": "sent from fetch post"
    })
  })
    .then(response => response.json())
    .then(responseJson => {

      const ticketIdString = responseJson.data.id;
      console.log(ticketIdString)

//this is the post request with the id from the send request above to check for errors
      fetch('https://exp.host/--/api/v2/push/getReceipts', {
        method: 'POST',
        headers: {
          Host: 'exp.host',
          Accept: 'application/json',
          'Accept-Encoding': 'gzip, deflate',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          "ids": [ticketIdString]
        })
      })
        .then(response => response.json())
        .then(receiptJson => {
          console.log('this is receipt json', receiptJson)
        })

      return;
    })
    .catch(error => {
      console.error(error);
    });
}

getNotifsFromApiAsync()

@charliecruzan Hey there I just want to update you on the code. I have a test build on my iPhone that is supposed to send a notification every two days.

Last night I kept the app open all night starting at 10 pm; at around 1 am I checked the app and noticed the screen had not updated as expected (it was still showing day from day before). So, I closed the app and opened it again and the HomeScreen updated as expected. This morning I saw a notification! :partying_face:

My question now is: how can I update the home screen without opening the app? or how can I update the data on the home screen without opening the app? Is the best option Task Manager? The docs says

“TaskManager works out of the box in the Expo client on Android, but on iOS you’ll need to test using a custom Expo client.”

When I look at the docs on building a custom Expo client it says:

Push Notifications are currently unavailable with ad hoc clients until we complete our work to add an extra authentication layer to the Expo Push Notification service.

I am trying to send local notifications when the app is not running. I am confused on how to use Task Manager because I don’t see an example that implements ‘background fetching.’ Are there any other examples of implementing Task Manager?

Why do you need to update the homescreen without opening the app?

Yes, the best way to do that is with TaskManager

Hey there.

I need to update the home screen in order to update a variable; the variable is based on today’s date. In my testing my app updates based on the date only when I quit and launch fresh for each day if; If leave the app open overnight it does not refresh at all because the entire interface is based on the variable in relation to today’s date.

Couldn’t you update the variable when the app is foregrounded? AppState · React Native

Thanks again for the quick reply. Yes that could work but I want to be able to send a notification based on a date; and I want to send a notification even if the user has not opened the app for that day. the app should automatically update the date and then trigger the notification based on today’s date.

I hope this makes sense. Basically the notification should be sent to the user even if the user has not opened the app in a long time but the notification is triggered by today’s date in relation to another upcoming day

I see what you’re saying, in that case yeah TaskManager is your best bet or you could send remote notifications from a server based on if your user has opened the app that day

One of the main issues is that the custom expo client build that is required to test task manager does not support notifications.

So your other option about sending notification from a remote server based on whether or not the user has open the app on that day could be useful, especially for testing. Do you have any other documentation on that? is it the same documentation on the notification API and notification guide?

it doesn’t support remote notifications, but I believe local notifications will work on a custom Expo client

Guide to sending remote notifications is in the same group of guides I shared here- Exponent

I looked at the API here but could not find any method based on if user opened device that day.

Can you point me in the direction where this method is (or provide more details)?

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