Closed ThugLifeAquatic closed 1 year ago
Using: "react-native": "0.69.4", "@notifee/react-native": "^7.4.0",
dependencies:
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation("com.squareup.okhttp3:okhttp")
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:30.2.0')
// Add the dependency for the Firebase SDK for Google Analytics
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
if (enableHermes) {
//noinspection GradleDynamicVersion
implementation("com.facebook.react:hermes-engine:+") {
// From node_modules
exclude group:'com.facebook.fbjni'
}
} else {
implementation jscFlavor
}
Trigger:
const trigger: TimestampTrigger = {
type: TriggerType.TIMESTAMP,
timestamp: targetDateTime.valueOf(),
repeatFrequency: RepeatFrequency.WEEKLY,
}
Trigger Notification:
await notifee.createTriggerNotification(
{
id: scheduleDay.valueOf().toString(),
title: notificationTitle,
body: String.format(
roundTripBody,
inboundMode.travelModeInfo?.displayName,
),
ios: {
categoryId: "confirmCommute",
},
android: {
channelId: channelId,
smallIcon: "ic_notification",
pressAction: {
id: "default",
},
actions: [
{
title: "Dismiss",
pressAction: {
id: "dismiss",
},
},
{
title: "Confirm commute",
pressAction: {
id: "confirm",
},
},
],
},
data: {
calendarDayDateString: commuteDay.dateValue.toString(),
date: moment.utc(commuteDay.dateValue).format(calendarDateFormat),
arrivalTime: targetDateTime.format(calendarTimeFormat),
distance: inboundMode.distance.toString(),
toMode: inboundMode.travelMode.valueOf(),
returnMode: inboundMode.travelMode.valueOf(),
},
},
trigger,
)
OnBackgroundEvent:
notifee.onBackgroundEvent(async ({ type, detail }) => {
const { notification, pressAction } = detail
if (
notification &&
type === EventType.ACTION_PRESS &&
pressAction?.id === "confirm"
) {
const params = {
date: notification.data.date,
arrivalTime: notification.data.arrivalTime,
toMode: notification.data.toMode,
toDistance: notification.data.distance,
isDayOff: false,
returnMode: notification.data.returnMode,
returnDistance: notification.data.distance,
}
//Log trip
await postRequest("calendar/editday", params)
}
// Check if the user pressed the "dismiss" action
if (
notification &&
type === EventType.ACTION_PRESS &&
pressAction?.id === "dismiss"
) {
// Remove the notification
await notifee.cancelNotification(notification.id)
}
})
@ThugLifeAquatic when you say it doesn't work, does your fetch to await postRequest(...)
fail?
I've taken a look and it looks like we can actually just remove this dependency from notifee.
But, the fact you need this or see a problem without there being any errors in the logs, makes me think that won't solve the problem you're facing.
What issues are you seeing when the OKHTTP client is broken?
Just trying to understand how you know it is the OKHTTP client.
@helenaford Sorry I got called away to work on something else. Just tested with latest release and same issue.
The only real clue in the "response" is: "stream was reset: HTTP_1_1_REQUIRED"
I specifically use this code in my android project to force OKHTTP to use HTTP_1_1.
@Override
public OkHttpClient createNewNetworkModuleClient() {
OkHttpClient.Builder client = OkHttpClientProvider.createClientBuilder()
.protocols(Util.immutableListOf(Protocol.HTTP_1_1));
return client.build();
}
It really seems to me that however Notifee is launching the app is preventing this client from being recreated/reused or whatever. I'm not super experienced in Native android so it's hard for me to say what's going on under the hood here.
Just saw this! Would you be able to make a repo public with the issue or some steps on how to reproduce the issue? Super weird what we could be doing in notifee that could be causing this issue... not sure if you've compared both notifee vs react-native-push-notifications but I know both uses alarm manager.
is this the line that's failing when a user presses confirm?
//Log trip
await postRequest("calendar/editday", params)
Would you be able to remove this from your deps as I'm assuming you added this before the latest version of notifee:
implementation("com.squareup.okhttp3:okhttp")
The other thing I'd suggest is to run our example app (packages/react-native/example
) locally, and make a request to an open API, for example:
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(json => console.log(json))
All my network requests fail after opening from a notifee notification. After a bit more digging I think this is what is happening, though I'm not sure why: https://github.com/facebook/react-native/issues/34789 This again points to my client not being initialized when launching from a notification.
I'll try your suggestions above.
Removing implementation("com.squareup.okhttp3:okhttp")
didn't do anything.
@ThugLifeAquatic do you have any custom android code? Or what are you using for the fetching i.e. what is this postRequest
funciton?
Did you try and replicate the issue in our example app?
Would love to get to the bottom of this.
Could it be a problem with react-native rather than notifee, based on the issue you linked above?
Hello ๐, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
Hi @helenaford and @ThugLifeAquatic , i'm facing a similar problem on my app did u guys find anything about this?
@fizefeko I reverted to React-Native-Push-Notifications to handle android notifications as I couldn't find a fix for this. I think this is a notifee issue since the above package works for android and Notifee does not.
My best guess as to why this is happening is Notifee is causing an http client to be instantiated before my app has a chance to set up the custom client it needs to function. I'm not sure why or how, maybe notifee is making some network calls before the app loads all the way, or creating a client for some other purpose. So the client is instantiated without the below code running, resulting in a client that does not use HTTP_1_1 and our api then rejects all of my requests.
@Override
public OkHttpClient createNewNetworkModuleClient() {
OkHttpClient.Builder client = OkHttpClientProvider.createClientBuilder()
.protocols(Util.immutableListOf(Protocol.HTTP_1_1));
return client.build();
}
I'd bet if you aren't doing anything custom in your OKHTTP client you likely won't see this issue.
Hello ๐, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
This is a weird one I've been struggling with for the last 2 weeks. Only affects android and only happens when the app has been killed. No errors are thrown by Notifee or OKHTTP. In fact it seems as if the OKHTTP client just doesn't exist when this happens. I added a logging interceptor to the client to try to see what was going on, but in this scenario the nothing is logged because the requests don't happen. If the app is in the background everything works fine. Closing the app and relaunching fixes the http issues.
At first I thought maybe it was an issue with Axios so I replaced it with Wretch. Didn't solve anything. Then I tried dozens of different configurations with different launch modes and intent flags and nothing helped. I tried reinitializing OKHTTP onStart() and that didn't work either. Finally I reverted to React-Native-Push-Notifications to see if the scheduled notifications caused the same issue and they do not. That library is no longer maintained and I doesn't offer all of the features I need so reverting back to that is not really an option. I've really been impressed with Notifee and want to continue using it but I've been pulling my hair out trying to solve this issue.
I realize this is a pretty nebulous bug report, but there aren't any errors thrown, and nothing stands out to me as unusual as far as my app configuration. I'm happy to answer any questions and provide further details.