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)