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)

 

posted @ 2024-04-14 23:51  洛晨随风  阅读(28)  评论(0编辑  收藏  举报