RN API基础操作篇
1.EXPO的项目环境下,允许应用访问手机媒体(例如相册)的方法
import * as MediaLibrary from 'expo-media-library'; const {status} = await MediaLibrary.requestPermissionsAsync(); if (status !== 'granted') { //未授权的话,返回 console.log('Permission to access location was denied'); return; }
2.允许获取位置的办法:
import * as Location from 'expo-location'; let { status } = await Location.requestForegroundPermissionsAsync(); if (status !== 'granted') { console.log('Permission to access location was denied'); return; } const location = await Location.getCurrentPositionAsync({}); const latitude = location.coords.latitude.toFixed(6) //纬度 const longitude = location.coords.longitude.toFixed(6) //经度
3.获取IP的办法:
import * as Network from 'expo-network'; const ip: any = await Network.getIpAddressAsync(); console.log('ip',ip)
积累小的知识,才能成就大的智慧,希望网上少一些复制多一些原创有用的答案