使用adb 监听react-native的日志 console.log输出

博客给出了一条信息技术相关的命令“adb logcat *:S ReactNative:V ReactNativeJS:V”,该命令可能用于过滤日志信息,在移动开发等场景中对日志进行筛选查看。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

adb logcat *:S ReactNative:V ReactNativeJS:V

我在expo沙盒环境中创建了reactnative项目,写了一个微信登录页面为import { View, Text, SafeAreaView, TouchableOpacity, Alert, Linking, StyleSheet } from 'react-native' import React, { useEffect } from 'react' const Login = () => { const handleWeChatLogin = async () => { try { // 检查是否安装了微信 const isWXInstalled = await Linking.canOpenURL('weixin://') if (!isWXInstalled) { Alert.alert('提示', '请先安装微信') return } // 构建微信登录 URL const appId = 'wxc063640eb0fd5cce' const redirectUri = encodeURIComponent('myapp://login') const scope = 'snsapi_userinfo' const state = Math.random().toString(36).substring(7) const wxUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect` console.log('微信登录跳转路径:', wxUrl) // 打开微信应用 await Linking.openURL('weixin://') // 监听URL变化 Linking.addEventListener('url', handleUrl) } catch (error) { console.error('微信登录失败:', error) Alert.alert('错误', '微信登录失败,请重试') } } const handleUrl = async (event: { url: string }) => { try { const { url } = event if (url.includes('code=')) { // 解析授权码 const code = url.split('code=')[1].split('&')[0] console.log('微信授权成功,code:', code) Alert.alert('成功', '微信登录成功!') // 这里可以发送 code 到后端服务器换取用户信息 // const response = await fetch('YOUR_BACKEND_URL/wechat/login', { // method: 'POST', // body: JSON.stringify({ code }), // }) // const userInfo = await response.json() } } catch (error) { console.error('处理授权结果失败:', error) Alert.alert('错误', '处理授权结果失败,请重试') } } return ( <SafeAreaView style={styles.container}> <View className='mt-10'> <Text style={styles.title}>登录页面</Text> <TouchableOpacity style={styles.wechatButton} onPress={handleWeChatLogin} > <Text style={styles.buttonText}>微信登录</Text> </TouchableOpacity> </View> </SafeAreaView> ) } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, title: { fontSize: 24, marginBottom: 30, color: '#333', textAlign: 'center' }, wechatButton: { backgroundColor: '#07C160', paddingHorizontal: 30, paddingVertical: 12, borderRadius: 5, marginHorizontal: 20 }, buttonText: { color: '#fff', fontSize: 16, fontWeight: 'bold', textAlign: 'center' }, }) export default Login现在能够选择微信,跳转至微信页面,但是没有微信授权页面,请解决,要求不能够跳转至浏览器页面
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木头杨x

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值