我正在尝试使用在 React Native 应用程序内的 web 视图中打开的页面的 postmessage。我尝试了很多次,但仍然无法发送。
我可以正常收听网页消息。我只是无法寄回任何东西。
我目前正在使用react-native-webview 11.6.5
export default function WebPage() {
const webviewRef = useRef();
const onMessage = (event) => {
//receive message from the web page. working here until here
const data = JSON.parse(event.nativeEvent.data);
//reply the message
webviewRef.current.postMessage(
JSON.stringify({reply: 'reply'}),
'*'
)
}
return <View>
<WebView
ref={webviewRef}
originWhitelist={['*']}
source={{ uri: 'https://robertnyman.com/html5/postMessage/postMessage.html' }}
domStorageEnabled
javaScriptEnabled
onMessage={onMessage}
/>
</View>
}
Run Code Online (Sandbox Code Playgroud)
有什么想法我做错了什么吗?
更新:
感谢@Ahmed Gaber 的帮助,我找到了这个问题https://github.com/react-native-webview/react-native-webview/issues/809并发现它们正在更改postMessage为injectJavaScript.
所以我将代码更新onMessage为以下内容:
const onMessage …Run Code Online (Sandbox Code Playgroud) webview reactjs react-native react-native-web react-native-webview
我正在使用时间戳属性在 Firestore 上保存一些帖子,然后查询按时间戳排序的帖子。我正在尝试创建一个“loadMore”函数,然后在用户滚动到底部并加载更多帖子时起作用。
我以这种方式保存帖子:
Firestore.instance
.collection('posts')
.add(<String, dynamic> {
'content': 'content,
'likes': 0,
'comments': 0,
'timestamp': DateTime.now(),
})
Run Code Online (Sandbox Code Playgroud)
并尝试以这种方式查询:
Firestore.instance
.collection('posts')
.orderBy('timestamp', descending: true)
.startAfter(
[]..add(posts.last.timestamp)
)
..limit(5)
Run Code Online (Sandbox Code Playgroud)
但是,它一直忽略“startAfter”并返回一个从集合的第一个元素而不是下一个元素开始的列表。
很想获得使用此类查询的帮助:)
我正在构建一个 Flutter 应用程序,用户可以在其中发布照片及其位置。使用既可以从相机中获取图片,也可以从库中获取图片。
如果用户从相机拍照,我可以使用设备的 GPS 位置来设置图片的位置。我试图根据图片的元数据获取图片的 GSP 位置,但是,我还没有找到方法。
有可能做到吗?怎么做最好?
编辑:我在问题中加入了“GPS”以使其清楚。我试图发现拍摄照片的物理位置。我还在问题中添加了“Flutter”,以表明我正面临在 Flutter App 中解决此问题的问题。
我一直坚持在使用 Redux 和 Redux-saga 的 gatsby 应用程序中使 firebase 工作。我知道存在,firebase-sagas但我正在尝试不使用它。
我正在尝试通过以下方式初始化 firebase 身份验证:
import * as firebase from 'firebase/app';
import 'firebase/auth';
export const app = firebase.initializeApp(
{
apiKey : "apiKey",
authDomain : "project.firebaseapp.com",
databaseURL : "https://project.firebaseio.com",
projectId : "project",
storageBucket : "project.appspot.com",
appId : "appId"
}
)
export const authRef = () => app.auth(); //also tried: firebase.auth() and firebase.auth(app)
//firebase.auth returns a function, but firebase.auth() throws error
Run Code Online (Sandbox Code Playgroud)
我有以下配置gatsby-node.js:
const path = require('path');
exports.onCreateWebpackConfig = ({ actions, plugins, …Run Code Online (Sandbox Code Playgroud) 我有一个使用 AWS Amplify 的 Expo 项目。我目前正在使用 Expo 的 EAS 在移动设备上进行部署。
\n我经常遇到这个错误:
\n\xe2\x9d\x8c Metro encountered an error:\nUnable to resolve module ./src/aws-exports from /Users/expo/workingdir/build/App.tsx:\n\nNone of these files exist:\n * src/aws-exports(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)\n * src/aws-exports/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)\n 11 | import Amplify from 'aws-amplify';\n> 12 | import awsconfig from './src/aws-exports';\n 15 | Amplify.configure(awsconfig);\nRun Code Online (Sandbox Code Playgroud)\n但是,我确实有该文件aws-exports,并且可以在本地正常运行。有时我可以毫无问题地构建。还没有弄清楚它何时发生或不发生的模式。
我怀疑这可能与gitignore(我认为EAS可能会在上传到服务器之前检查它)有关。我已经尝试运行该命令--clear-cache,但没有注意到任何效果。
关于我能做什么有什么建议吗?:)
\n我正在尝试在 Google Analytics 上跟踪 chrome 扩展程序。
看起来它配置正确,但我看不到仪表板上的数据。不确定它是否是延迟,是否因为我在开发模式下运行扩展而被忽略,或者我是否需要配置其他东西。
我正在使用以下代码:
const gaScript = document.createElement('script');
gaScript.type = 'text/javascript';
gaScript.async = true;
gaScript.src = 'https://ssl.google-analytics.com/analytics.js';
gaScript.onload = function() {
ga.l = +new Date;
ga('create', 'MY_CODE', 'auto');
ga('set', 'checkProtocolTask', null); // Disables file protocol checking.
ga('send', 'pageview');
}
const s = document.getElementsByTagName('script')[0];
s.parentNode?.insertBefore(gaScript, s);
Run Code Online (Sandbox Code Playgroud)
当我检查后台控制台时,在“网络”选项卡上,我可以看到:
但我仍然无法在分析仪表板上看到记录的数据。知道为什么会这样吗?
多亏了米歇尔,我才能够理解这个问题。Google 创建了一种新的跟踪形式:Global Analytics,其代码不同于标准的 Universal Analytics。
今天创建分析项目的人将默认获得全局分析。我研究了它,我认为该标准现在更适合扩展。我会等待 Google 更新他们的文档以包含此案例以开始使用它
javascript analytics google-analytics google-chrome-extension
我正在尝试使用 NextJS 生成我网站的站点地图。但它确实有很多链接。我想避免处理每个访问 sitemap.xml 的所有链接。
我有这样的事情:
import { GetServerSideProps } from "next";
import React from "react";
const Sitemap = () => {
return null;
};
export const getServerSideProps: GetServerSideProps = async ({ res }) => {
const BASE_URL = "http://localhost:3000";
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{generateSitemap()}
</sitemapindex>`;
res.setHeader("Content-Type", "text/xml");
res.write(sitemap);
res.end();
return {
props: {},
};
};
export default Sitemap;
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
export const getStaticProps: GetStaticProps<PageProps> = async () => {
try {
const sitemap = await generateSiteMap(); …Run Code Online (Sandbox Code Playgroud) 在尝试将我的项目迁移到 AndroidX 后,我遇到了很多问题,但仍然无法成功构建。
现在,当我尝试构建时,出现以下错误:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
* Error running Gradle:
ProcessException: Process "/Users/felipe/MYAPPANAME/android/gradlew" exited abnormally:
> Configure project :app
WARNING: minSdkVersion (21) is greater than targetSdkVersion (18) for variant "debug". Please change the values such that minSdkVersion is less than or equal to targetSdkVersion.
WARNING: minSdkVersion (21) is greater than targetSdkVersion (18) for variant "dynamicProfile". Please change the values such that minSdkVersion is less than or equal to targetSdkVersion.
WARNING: minSdkVersion …Run Code Online (Sandbox Code Playgroud) flutter ×3
firebase ×2
javascript ×2
reactjs ×2
analytics ×1
android ×1
aws-amplify ×1
dart ×1
expo ×1
fastlane ×1
gatsby ×1
geolocation ×1
gradle ×1
next.js ×1
react-native ×1
react-redux ×1
sitemap ×1
typescript ×1
vercel ×1
webpack ×1
webview ×1