React Native iOS send notification through receiving socket.io from the server in background mode

时间秒杀一切 提交于 2019-12-10 12:23:24

问题


I am using react-native-notification module to send a local notification when I receive a socket.io event sent from the server. The notification is properly configured and works on both iOS and Android in foreground mode. However, due to the fact that Apple doesn't allow Apps to run on the background except for (Audio, navigation map, etc.), I am not able to receive any socket events when my app is not on the background and temporarily suspended.

I'm therefore not able to send a local notification to the iOS device since the app isn't really running once I switch the app to background.

Here I'm asking for possible solutions to my current problem.

This could be a general question regarding react native or iOS native.

Everything works well on Android devices and I don't think there is anything wrong with my code so I don't know what code I should display here.

In short, I just want to know how to receive socket events when the app is in the background on an iOS device, or if that can't be achieved. I would like to know how most apps even send notifications to their users when their apps are in the background.(I do not want to cheat the system and set the background mode to audio).


回答1:


I know its a old post but if anyone still wondering, You can send notification even your app is closed or socket disconnected. You can use firebase push notification which will handle your current situation even if your app is killed.

Try below plugin to send notification to both android/ios without using any background service react-native-firebase



来源:https://stackoverflow.com/questions/48054982/react-native-ios-send-notification-through-receiving-socket-io-from-the-server-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!