简体   繁体   English

在本机应用程序和移动浏览器之间共享数据

[英]Share data between native app and mobile browser

I have a native application which installed on a client mobile device.我有一个安装在客户端移动设备上的本机应用程序。 Other than that, I have a web application that this client can access via a mobile browser.除此之外,我有一个 web 应用程序,这个客户端可以通过移动浏览器访问它。

I would like to sync and pass information (such as identifiers or other user data) between the application and the web browser.我想在应用程序和 web 浏览器之间同步和传递信息(例如标识符或其他用户数据)。 Is there any WebAPI that can help me do so?是否有任何 WebAPI 可以帮助我这样做?

I found the getInstalledRelatedApps that can indicate me whether my application installed or not, but what about sharing an information between those two?我发现getInstalledRelatedApps可以指示我的应用程序是否已安装,但是如何在这两者之间共享信息呢? Is it possible somehow?有可能吗?

What frameworks are you using?你使用什么框架? Can I consider that you are using Node JS, React and React Native?我可以认为您正在使用 Node JS、React 和 React Native 吗?

You could use express in the backend to create your own API, call it on the Frontend/Mobile with Axios, and then you could pass the parameters by setting them on the route.您可以在后端使用 express 创建自己的 API,在 Frontend/Mobile 上使用 Axios 调用它,然后您可以通过在路由上设置参数来传递参数。 IE let's say that you want to pass on the tea ID from the mobile app to the web app so you can see them on your navigator: IE 假设您想将茶 ID 从移动应用程序传递到 web 应用程序,以便您可以在导航器上看到它们:

// BACKEND
const express = require('express');
const routes = express.Router();

routes.get('/tea/:teaId', function (req, res) {
  res.send(req.params);
});

module.exports = routes;


// MOBILE
import React from 'react';
import axios from 'axios';
import { Linking } from 'react-native';

const api = axios.create({
  baseURL: 'http://your-url-here.com/',
});

let teaID = 22;

function sendToWeb() {
  Linking.openURL(`https://your-url-here.com/tea/${teaID}`)
}

You can also pass Header Authorization in case that you want the user to be logged on and skip the login step or something related to it.您还可以通过 Header 授权,以防您希望用户登录并跳过登录步骤或与之相关的内容。

Express Routing快速路由

About Axios关于Axios

I hope that this can help you a bit, And sorry if it seems confusing, it's my first time trying to answer a question!我希望这可以帮助你一点,如果它看起来令人困惑,很抱歉,这是我第一次尝试回答问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM