React Native iOS 通过在后台模式下从服务器接收 socket.io 发送通知 [英] React Native iOS send notification through receiving socket.io from the server in background mode

查看:61
本文介绍了React Native iOS 通过在后台模式下从服务器接收 socket.io 发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我收到服务器发送的 socket.io 事件时,我正在使用 react-native-notification 模块发送本地通知.通知已正确配置,可在前台模式下在 iOS 和 Android 上运行.但是,由于Apple不允许应用程序在后台运行,除了(音频,导航地图等),当我的应用程序不在后台并暂时暂停时,我无法接收任何套接字事件.

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.

因此,我无法向 iOS 设备发送本地通知,因为一旦我将应用切换到后台,应用就没有真正运行.

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.

这可能是关于 react native 或 iOS native 的一般问题.

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

在 Android 设备上一切正常,我认为我的代码没有任何问题,所以我不知道我应该在这里显示什么代码.

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.

简而言之,我只想知道当应用程序在 iOS 设备的后台时如何接收套接字事件,或者如果无法实现.我想知道当他们的应用程序在后台时,大多数应用程序如何向用户发送通知.(我不想欺骗系统并将后台模式设置为音频).

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).

推荐答案

我知道这是一个旧帖子,但如果有人仍然想知道,即使您的应用程序关闭或套接字断开连接,您也可以发送通知.您可以使用 firebase 推送通知,即使您的应用被终止,它也会处理您当前的情况.

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.

尝试使用下面的插件在不使用任何后台服务的情况下向 android/ios 发送通知 react-native-firebase

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

这篇关于React Native iOS 通过在后台模式下从服务器接收 socket.io 发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆