非常教程

React native参考手册

APIs

Geolocation

Geolocation API扩展了Web规范:https://developer.mozilla.org/en-US/docs/Web/API/Geolocation

作为浏览器的polyfill,这个API可以通过navigator.geolocation全局使用 - 你不需要import它。

配置和权限

只有原生代码的项目

本部分仅适用于react-native init使用Create React Native App创建的项目或已经退出的项目。有关弹出的更多信息,请参阅创建React Native App存储库的指南。

iOS

您需要NSLocationWhenInUseUsageDescription在Info.plist中包含密钥才能在使用该应用时启用地理位置。当您使用创建项目时,默认情况下启用地理定位react-native init

为了在后台启用地理位置,您需要在Info.plist中包含'NSLocationAlwaysUsageDescription'键,并在Xcode的'功能'选项卡中添加位置作为背景模式。

Android

要请求访问位置,您需要将以下行添加到您的应用AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Android API> = 18位置还将包含一个mocked布尔值,以指示位置是否是从模拟提供者创建的。

方法

static setRNConfiguration(config)

设置将在所有位置请求中使用的配置选项。

选项

iOS

  • skipPermissionRequests- 默认为false,如果true您在使用Geolocation API之前必须请求权限。

static requestAuthorization()

根据pList上配置的密钥请求合适的位置权限。如果设置了NSLocationAlwaysUsageDescription,它将请求总是授权,但如果设置NSLocationWhenInUseUsageDescription,它将请求InUse授权。

static getCurrentPosition(geo_success, geo_error?, geo_options?)

用最新的位置信息调用一次成功回调。支持的选项:timeout(ms),maximumAge(ms),enableHighAccuracy(bool)在Android上,如果位置被缓存,可以立即返回,或者它会请求更新,这可能需要一段时间。

static watchPosition(success, error?, options?)

每当位置发生变化时调用成功回调。支持的选项:timeout(ms),maximumAge(ms),enableHighAccuracy(bool),distanceFilter(m),useSignificantChanges(bool)

static clearWatch(watchID)

static stopObserving()

React native

React Native 是一个 JavaScript 的框架,用来撰写实时的、可原生呈现 iOS 和 Android 的应用。

主页 https://facebook.github.io/react-native/
源码 https://github.com/facebook/react-native
发布版本 0.49

React native目录

1.开始 | Getting Started
2.指南 | Guides
3.APIs
4.组件:ActivityIndicator | Components: ActivityIndicator
5.组件:按钮 | Components: Button
6.组件:CheckBox | Components: CheckBox
7.组件:DatePickerIOS | Components: DatePickerIOS
8.组件:DrawerLayoutAndroid | Components: DrawerLayoutAndroid
9.组件:FlatList | Components: FlatList
10.组件:图像 | Components: Image
11.组件:KeyboardAvoidingView | Components: KeyboardAvoidingView
12.Components: ListView
13.Components: MaskedViewIOS
14.Components: Modal
15.Components: NavigatorIOS
16.Components: Picker
17.Components: PickerIOS
18.Components: ProgressBarAndroid
19.Components: ProgressViewIOS
20.Components: RefreshControl
21.Components: ScrollView
22.Components: SectionList
23.Components: SegmentedControlIOS
24.Components: Slider
25.Components: SnapshotViewIOS
26.Components: StatusBar
27.Components: Switch
28.Components: TabBarIOS
29.Components: TabBarIOS.Item
30.Components: Text
31.Components: TextInput
32.Components: ToolbarAndroid
33.Components: TouchableHighlight
34.Components: TouchableNativeFeedback
35.Components: TouchableOpacity
36.Components: TouchableWithoutFeedback
37.Components: View
38.Components: ViewPagerAndroid
39.Components: VirtualizedList
40.Components: WebView
41.创建 | Contributing
42.指南(Android) | Guides (Android)
43.指南(IOS) | Guides (iOS)
44.其他 | Miscellaneous