├── .gitignore ├── .npmignore ├── LICENSE ├── LocationSwitch.js ├── README.md ├── android ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── org │ └── pweitz │ └── reactnative │ └── locationswitch │ ├── LocationSwitch.java │ ├── LocationSwitchPackage.java │ └── Module.java ├── index.android.js ├── index.ios.js ├── index.js ├── ios ├── RNReactNativeLocationSwitch.h ├── RNReactNativeLocationSwitch.m ├── RNReactNativeLocationSwitch.xcodeproj │ └── project.pbxproj └── ReactNativeAndroidLocationSwitch.podspec ├── package.json └── preview ├── previewAndroid.gif └── previewIOS.gif /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | #*.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | 45 | # Keystore files 46 | *.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json 58 | 59 | 60 | # Xcode 61 | # 62 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 63 | 64 | ## Build generated 65 | DerivedData/ 66 | 67 | ## Various settings 68 | *.pbxuser 69 | !default.pbxuser 70 | *.mode1v3 71 | !default.mode1v3 72 | *.mode2v3 73 | !default.mode2v3 74 | *.perspectivev3 75 | !default.perspectivev3 76 | xcuserdata/ 77 | project.xcworkspace/ 78 | 79 | ## Other 80 | *.moved-aside 81 | *.xccheckout 82 | *.xcscmblueprint 83 | 84 | ## Obj-C/Swift specific 85 | *.hmap 86 | *.ipa 87 | *.dSYM.zip 88 | *.dSYM 89 | 90 | # CocoaPods 91 | # 92 | # We recommend against adding the Pods directory to your .gitignore. However 93 | # you should judge for yourself, the pros and cons are mentioned at: 94 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 95 | # 96 | # Pods/ 97 | 98 | # Carthage 99 | # 100 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 101 | # Carthage/Checkouts 102 | 103 | Carthage/Build 104 | 105 | # fastlane 106 | # 107 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 108 | # screenshots whenever they are needed. 109 | # For more information about the recommended setup visit: 110 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 111 | 112 | fastlane/report.xml 113 | fastlane/Preview.html 114 | fastlane/screenshots 115 | fastlane/test_output 116 | 117 | # Code Injection 118 | # 119 | # After new code Injection tools there's a generated folder /iOSInjectionProject 120 | # https://github.com/johnno1962/injectionforxcode 121 | 122 | iOSInjectionProject/ -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | android/build 3 | android/build/* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /LocationSwitch.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import {AppState, NativeModules, Platform} from "react-native"; 4 | 5 | const locationSwitchModule = NativeModules.RNReactNativeLocationSwitch; 6 | 7 | const APP_STATE_HANDLER_NAME = 'change'; 8 | 9 | 10 | let sSuccessCallback; 11 | let sErrorCallback; 12 | 13 | 14 | function handleAppStateChange(nextAppState) { 15 | if (Platform.OS === 'ios' && nextAppState === 'active') { 16 | removeAppStateListener(); 17 | locationSwitchModule.isLocationEnabled(onIOSSuccessCallback, onIOSErrorCallback); 18 | } 19 | } 20 | 21 | function removeAppStateListener() { 22 | if (Platform.OS === 'ios') { 23 | AppState.removeEventListener(APP_STATE_HANDLER_NAME, handleAppStateChange); 24 | } 25 | } 26 | 27 | function addAppStateListener() { 28 | if (Platform.OS === 'ios') { 29 | AppState.addEventListener(APP_STATE_HANDLER_NAME, handleAppStateChange); 30 | } 31 | } 32 | 33 | function onIOSSuccessCallback() { 34 | removeAppStateListener(); 35 | if (sSuccessCallback) { 36 | sSuccessCallback(); 37 | } 38 | } 39 | 40 | function onIOSErrorCallback() { 41 | removeAppStateListener(); 42 | if (sErrorCallback) { 43 | sErrorCallback(); 44 | } 45 | } 46 | 47 | 48 | const LocationSwitch = { 49 | 50 | isLocationEnabled(successCallback, errorCallback) { 51 | if (Platform.OS === 'ios') { 52 | locationSwitchModule.isLocationEnabled(successCallback, errorCallback); 53 | } else { 54 | locationSwitchModule.isLocationEnabled(successCallback, errorCallback); 55 | } 56 | }, 57 | 58 | enableLocationService(interval, requestHighAccuracy, successCallback, errorCallback) { 59 | if (Platform.OS === 'ios') { 60 | sSuccessCallback = successCallback; 61 | sErrorCallback = errorCallback; 62 | 63 | addAppStateListener(); 64 | locationSwitchModule.enableLocationService(onIOSSuccessCallback, onIOSErrorCallback); 65 | 66 | } else { 67 | locationSwitchModule.enableLocationService(interval, requestHighAccuracy, successCallback, errorCallback); 68 | } 69 | }, 70 | 71 | }; 72 | 73 | export default LocationSwitch; 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # React Native Location Switch 3 | 4 | A react Native module to enable location based services on Android and IOS. 5 | 6 | 7 | 8 | ## Requirements 9 | - react-native >= 0.38.0 10 | - android buildToolsVersion 26.0.1 11 | - gradle build tools 2.3.3 12 | 13 | 14 | ## Installation Android 15 | 16 | 1. npm install react-native-location-switch 17 | 18 | 2. add the following 2 lines to your /android/settings.gradle file 19 | ``` 20 | include ':react-native-location-switch' 21 | project(':react-native-location-switch').projectDir = new File(settingsDir, '../node_modules/react-native-location-switch/android') 22 | ``` 23 | 24 | 3. add the following line to your /android/app/build.gradle file 25 | ``` 26 | compile project(':react-native-location-switch') 27 | ``` 28 | 29 | 4. add the "LocationSwitchPackage" import into your MainApplication.java file: 30 | ```java 31 | import org.pweitz.reactnative.locationswitch.LocationSwitchPackage; 32 | ``` 33 | 34 | 5. add the "LocationSwitchPackage" into your MainApplication.java file (getPackages method): 35 | ```java 36 | @Override 37 | protected List getPackages() { 38 | return Arrays.asList( 39 | new MainReactPackage(), 40 | ... // your other react native packages 41 | new LocationSwitchPackage() 42 | ); 43 | } 44 | 45 | ``` 46 | 6. add the "LocationSwitch" import into your MainActivity.java file: 47 | ```java 48 | import org.pweitz.reactnative.locationswitch.LocationSwitch; 49 | ``` 50 | 51 | 7. add the following code into your MainActivity.java file: 52 | ```java 53 | @Override 54 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 55 | super.onActivityResult(requestCode, resultCode, data); 56 | LocationSwitch.getInstance().onActivityResult(requestCode, resultCode); 57 | } 58 | ``` 59 | 60 | ## Installation IOS 61 | 62 | 1. Open the project in xCode, left click on the Libraries folder -> Add files to ... and select 63 | ``` 64 | ./node_modules/react-native-location-switch/ios/RNReactNativeLocationSwitch.xcodeproj 65 | ``` 66 | 67 | 2. Open the project -> Build Phases -> Link Binary With Libraries and select libRNReactNativeLocationSwitch.a 68 | 69 | 70 | ## React Native Interface 71 | 72 | ```javascript 73 | LocationSwitch.enableLocationService( 74 | interval, 75 | requestHighAccuracy, 76 | successCallback, 77 | errorCallback 78 | ); 79 | ``` 80 | ```javascript 81 | LocationSwitch.isLocationEnabled( 82 | successCallback, 83 | errorCallback 84 | ); 85 | ``` 86 | 87 | Option | Default | Info 88 | ------ | ------- | ---- 89 | interval | 1000 | Update interval in ms (ignored on IOS) 90 | requestHighAccuracy | false | If true, highest accuracy is requested. If false, "block" level accuracy is requested (ignored on IOS) 91 | successCallback | null | Is called when the user allows access to the location services or when the location services are already enabled 92 | errorCallback | null | Is called when the user denies access to the location services 93 | 94 | ## Usage 95 | 96 | ```javascript 97 | import React, { Component } from 'react'; 98 | import { AppRegistry, Text, View, TouchableOpacity, StyleSheet, Alert } from 'react-native'; 99 | import LocationSwitch from 'react-native-location-switch'; 100 | 101 | const style = StyleSheet.create({ 102 | container: { 103 | flex: 1, 104 | alignItems: 'center', 105 | justifyContent: 'center', 106 | }, 107 | button: { 108 | padding: 20, 109 | }, 110 | text: { 111 | fontSize: 20, 112 | }, 113 | textSuccess: { 114 | fontSize: 20, 115 | color: 'green', 116 | }, 117 | }); 118 | 119 | export default class LocationSwitchApp extends Component { 120 | 121 | constructor(props) { 122 | super(props); 123 | 124 | this.state = { locationEnabled: false }; 125 | this.onEnableLocationPress = this.onEnableLocationPress.bind(this); 126 | } 127 | 128 | componentDidMount() { 129 | LocationSwitch.isLocationEnabled( 130 | () => { 131 | Alert.alert('Location is enabled'); 132 | this.setState({ locationEnabled: true }); 133 | }, 134 | () => { Alert.alert('Location is disabled'); }, 135 | ); 136 | } 137 | 138 | onEnableLocationPress() { 139 | LocationSwitch.enableLocationService(1000, true, 140 | () => { this.setState({ locationEnabled: true }); }, 141 | () => { this.setState({ locationEnabled: false }); }, 142 | ); 143 | } 144 | 145 | renderLocationStatus() { 146 | if (this.state.locationEnabled) { 147 | return Location enabled; 148 | } 149 | return Location disabled; 150 | } 151 | 152 | render() { 153 | return ( 154 | 155 | 156 | Enable location service 157 | 158 | {this.renderLocationStatus()} 159 | 160 | ); 161 | } 162 | } 163 | 164 | AppRegistry.registerComponent('reactClientSandbox', () => LocationSwitchApp); 165 | ``` 166 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | import groovy.json.JsonSlurper 2 | 3 | def computeVersionName() { 4 | // dynamically retrieve version from package.json 5 | def slurper = new JsonSlurper() 6 | def json = slurper.parse(file('../package.json'), "utf-8") 7 | return json.version 8 | } 9 | 10 | buildscript { 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | dependencies { 16 | classpath 'com.android.tools.build:gradle:2.3.3' 17 | } 18 | } 19 | 20 | apply plugin: 'com.android.library' 21 | 22 | android { 23 | compileSdkVersion 26 24 | buildToolsVersion "26.0.1" 25 | 26 | defaultConfig { 27 | minSdkVersion 16 28 | targetSdkVersion 26 29 | versionCode 1 30 | versionName computeVersionName() 31 | } 32 | lintOptions { 33 | abortOnError false 34 | } 35 | } 36 | 37 | repositories { 38 | mavenCentral() 39 | } 40 | 41 | 42 | dependencies { 43 | compile 'com.facebook.react:react-native:+' 44 | compile 'com.google.android.gms:play-services-location:11.0.0' 45 | } 46 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiWeitz/react-native-location-switch/835f37bffac46b221c7a372069699b304fb4ccb4/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Aug 26 16:46:11 EEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/java/org/pweitz/reactnative/locationswitch/LocationSwitch.java: -------------------------------------------------------------------------------- 1 | package org.pweitz.reactnative.locationswitch; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.IntentSender; 6 | import android.location.LocationManager; 7 | import android.util.Log; 8 | 9 | import com.facebook.react.bridge.Callback; 10 | import com.google.android.gms.common.api.GoogleApiClient; 11 | import com.google.android.gms.common.api.PendingResult; 12 | import com.google.android.gms.common.api.ResultCallback; 13 | import com.google.android.gms.common.api.Status; 14 | import com.google.android.gms.location.LocationRequest; 15 | import com.google.android.gms.location.LocationServices; 16 | import com.google.android.gms.location.LocationSettingsRequest; 17 | import com.google.android.gms.location.LocationSettingsResult; 18 | import com.google.android.gms.location.LocationSettingsStatusCodes; 19 | 20 | public class LocationSwitch { 21 | 22 | private static final String TAG = "LocationSwitch"; 23 | protected static final int REQUEST_CHECK_SETTINGS = 0x1; 24 | 25 | private static final LocationSwitch instance = new LocationSwitch(); 26 | 27 | private int mInterval = 1000; 28 | private Callback mErrorCallback; 29 | private Callback mSuccessCallback; 30 | private int mAccuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; 31 | 32 | 33 | private LocationSwitch() { 34 | 35 | } 36 | 37 | 38 | public static LocationSwitch getInstance() { 39 | return instance; 40 | } 41 | 42 | 43 | public void setup(final Callback successCallback, final Callback errorCallback, 44 | final int interval, final boolean requestHighAccuracy) { 45 | mInterval = interval; 46 | mErrorCallback = errorCallback; 47 | mSuccessCallback = successCallback; 48 | 49 | if (requestHighAccuracy) { 50 | mAccuracy = LocationRequest.PRIORITY_HIGH_ACCURACY; 51 | } else { 52 | mAccuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; 53 | } 54 | } 55 | 56 | 57 | public void displayLocationSettingsRequest(final Activity activity) { 58 | GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity) 59 | .addApi(LocationServices.API).build(); 60 | googleApiClient.connect(); 61 | 62 | LocationRequest locationRequest = LocationRequest.create(); 63 | locationRequest.setPriority(mAccuracy); 64 | locationRequest.setInterval(mInterval); 65 | locationRequest.setFastestInterval(mInterval / 2); 66 | 67 | LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder() 68 | .addLocationRequest(locationRequest); 69 | builder.setAlwaysShow(false); 70 | 71 | final PendingResult result = 72 | LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build()); 73 | result.setResultCallback(new LocationResultCallback(activity)); 74 | } 75 | 76 | 77 | public void onActivityResult(int requestCode, int resultCode) { 78 | switch (requestCode) { 79 | case REQUEST_CHECK_SETTINGS: 80 | switch (resultCode) { 81 | case Activity.RESULT_OK: 82 | callSuccessCallback(); 83 | break; 84 | case Activity.RESULT_CANCELED: 85 | callErrorCallback(); 86 | break; 87 | } 88 | break; 89 | } 90 | } 91 | 92 | 93 | public void isLocationEnabled(final Activity activity, final Callback successCallback, 94 | final Callback errorCallback) { 95 | 96 | LocationManager lm = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE); 97 | boolean gps_enabled = false; 98 | boolean network_enabled = false; 99 | 100 | try { 101 | gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); 102 | } catch(Exception ex) {} 103 | 104 | try { 105 | network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); 106 | } catch(Exception ex) {} 107 | 108 | if(gps_enabled || network_enabled) { 109 | successCallback.invoke(); 110 | } else { 111 | errorCallback.invoke(); 112 | } 113 | } 114 | 115 | 116 | private void callSuccessCallback() { 117 | if (null != mSuccessCallback) { 118 | mSuccessCallback.invoke(); 119 | } 120 | } 121 | 122 | 123 | private void callErrorCallback() { 124 | if (null != mErrorCallback) { 125 | mErrorCallback.invoke(); 126 | } 127 | } 128 | 129 | 130 | private class LocationResultCallback implements ResultCallback { 131 | 132 | private Activity mActivity; 133 | 134 | public LocationResultCallback(Activity activity) { 135 | mActivity = activity; 136 | } 137 | 138 | @Override 139 | public void onResult(LocationSettingsResult result) { 140 | final Status status = result.getStatus(); 141 | switch (status.getStatusCode()) { 142 | case LocationSettingsStatusCodes.SUCCESS: 143 | // All location settings are satisfied -> nothing to do 144 | callSuccessCallback(); 145 | break; 146 | case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: 147 | // Location settings are not satisfied. Show the user a dialog to upgrade location settings 148 | try { 149 | // Show the dialog by calling startResolutionForResult(), and check the result 150 | status.startResolutionForResult(mActivity, REQUEST_CHECK_SETTINGS); 151 | } catch (IntentSender.SendIntentException e) { 152 | Log.e(TAG, "PendingIntent unable to execute request.", e); 153 | callErrorCallback(); 154 | } 155 | break; 156 | case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: 157 | Log.e(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created."); 158 | callErrorCallback(); 159 | break; 160 | } 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /android/src/main/java/org/pweitz/reactnative/locationswitch/LocationSwitchPackage.java: -------------------------------------------------------------------------------- 1 | package org.pweitz.reactnative.locationswitch; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | public class LocationSwitchPackage implements ReactPackage { 14 | 15 | public List> createJSModules() { 16 | return Collections.emptyList(); 17 | } 18 | 19 | @Override 20 | public List createViewManagers(ReactApplicationContext reactContext) { 21 | return Collections.emptyList(); 22 | } 23 | 24 | @Override 25 | public List createNativeModules( 26 | ReactApplicationContext reactContext) { 27 | List modules = new ArrayList<>(); 28 | 29 | modules.add(new Module(reactContext)); 30 | 31 | return modules; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /android/src/main/java/org/pweitz/reactnative/locationswitch/Module.java: -------------------------------------------------------------------------------- 1 | package org.pweitz.reactnative.locationswitch; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | 6 | import com.facebook.react.bridge.ActivityEventListener; 7 | import com.facebook.react.bridge.Callback; 8 | import com.facebook.react.bridge.ReactApplicationContext; 9 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 10 | import com.facebook.react.bridge.ReactMethod; 11 | 12 | 13 | public class Module extends ReactContextBaseJavaModule implements ActivityEventListener { 14 | 15 | 16 | public Module(ReactApplicationContext reactContext) { 17 | super(reactContext); 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return "RNReactNativeLocationSwitch"; 23 | } 24 | 25 | @ReactMethod 26 | public void isLocationEnabled(Callback successCallback, Callback errorCallback) { 27 | LocationSwitch.getInstance().isLocationEnabled(getCurrentActivity(), 28 | successCallback, errorCallback); 29 | } 30 | 31 | @ReactMethod 32 | public void enableLocationService(int interval, boolean requestHighAccuracy, 33 | Callback successCallback, Callback errorCallback) { 34 | LocationSwitch.getInstance().setup( 35 | successCallback, errorCallback, interval, requestHighAccuracy); 36 | LocationSwitch.getInstance().displayLocationSettingsRequest( 37 | getCurrentActivity()); 38 | } 39 | 40 | 41 | /** 42 | * ActivityEventListener methods 43 | **/ 44 | public void onNewIntent(Intent intent) { 45 | 46 | } 47 | 48 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 49 | LocationSwitch.getInstance().onActivityResult(requestCode, resultCode); 50 | } 51 | 52 | public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { 53 | LocationSwitch.getInstance().onActivityResult(requestCode, resultCode); 54 | } 55 | } -------------------------------------------------------------------------------- /index.android.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import LocationSwitch from './LocationSwitch'; 4 | 5 | export default LocationSwitch; 6 | -------------------------------------------------------------------------------- /index.ios.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import LocationSwitch from './LocationSwitch'; 4 | 5 | export default LocationSwitch; 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import LocationSwitch from './LocationSwitch'; 4 | 5 | export default LocationSwitch; 6 | -------------------------------------------------------------------------------- /ios/RNReactNativeLocationSwitch.h: -------------------------------------------------------------------------------- 1 | 2 | #if __has_include("RCTBridgeModule.h") 3 | #import "RCTBridgeModule.h" 4 | #else 5 | #import 6 | #endif 7 | 8 | @interface RNReactNativeLocationSwitch : NSObject 9 | 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /ios/RNReactNativeLocationSwitch.m: -------------------------------------------------------------------------------- 1 | 2 | #import "RNReactNativeLocationSwitch.h" 3 | #import "UIKit/UIKit.h" 4 | #import 5 | #import 6 | 7 | @implementation RNReactNativeLocationSwitch 8 | 9 | - (dispatch_queue_t)methodQueue 10 | { 11 | return dispatch_get_main_queue(); 12 | } 13 | RCT_EXPORT_MODULE() 14 | 15 | 16 | RCT_REMAP_METHOD(enableLocationService, 17 | onPermissionGiven:(RCTResponseSenderBlock)successCallback 18 | onPermissionDenied:(RCTResponseSenderBlock)errorCallback) 19 | { 20 | CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; 21 | 22 | if (![CLLocationManager locationServicesEnabled]) { 23 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"] options:@{} 24 | completionHandler:^(BOOL success) {}]; 25 | 26 | } else if (status == kCLAuthorizationStatusDenied) { 27 | NSLog(@"Location Services Disabled"); 28 | 29 | // show location settings 30 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} 31 | completionHandler:^(BOOL success) {}]; 32 | 33 | } else { 34 | NSLog(@"Location Services Enabled"); 35 | successCallback(@[[NSNull null]]); 36 | } 37 | } 38 | 39 | 40 | RCT_REMAP_METHOD(isLocationEnabled, 41 | onLocationEnabled:(RCTResponseSenderBlock)successCallback 42 | onLocationDisable:(RCTResponseSenderBlock)errorCallback) 43 | { 44 | CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; 45 | 46 | if (![CLLocationManager locationServicesEnabled] || status == kCLAuthorizationStatusDenied) { 47 | NSLog(@"Location Services Disabled"); 48 | errorCallback(@[[NSNull null]]); 49 | } else { 50 | NSLog(@"Location Services Enabled"); 51 | successCallback(@[[NSNull null]]); 52 | } 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /ios/RNReactNativeLocationSwitch.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B3E7B58A1CC2AC0600A0062D /* RNReactNativeLocationSwitch.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNReactNativeLocationSwitch.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 134814201AA4EA6300B7C361 /* libRNReactNativeLocationSwitch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNReactNativeLocationSwitch.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | B3E7B5881CC2AC0600A0062D /* RNReactNativeLocationSwitch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNReactNativeLocationSwitch.h; sourceTree = ""; }; 28 | B3E7B5891CC2AC0600A0062D /* RNReactNativeLocationSwitch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNReactNativeLocationSwitch.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 134814211AA4EA7D00B7C361 /* Products */ = { 43 | isa = PBXGroup; 44 | children = ( 45 | 134814201AA4EA6300B7C361 /* libRNReactNativeLocationSwitch.a */, 46 | ); 47 | name = Products; 48 | path = "/Users/philippw/projects/home/react-native/react-native-android-location-switch/ios/build"; 49 | sourceTree = ""; 50 | }; 51 | 58B511D21A9E6C8500147676 = { 52 | isa = PBXGroup; 53 | children = ( 54 | B3E7B5881CC2AC0600A0062D /* RNReactNativeLocationSwitch.h */, 55 | B3E7B5891CC2AC0600A0062D /* RNReactNativeLocationSwitch.m */, 56 | 134814211AA4EA7D00B7C361 /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | /* End PBXGroup section */ 61 | 62 | /* Begin PBXNativeTarget section */ 63 | 58B511DA1A9E6C8500147676 /* RNReactNativeLocationSwitch */ = { 64 | isa = PBXNativeTarget; 65 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNReactNativeLocationSwitch" */; 66 | buildPhases = ( 67 | 58B511D71A9E6C8500147676 /* Sources */, 68 | 58B511D81A9E6C8500147676 /* Frameworks */, 69 | 58B511D91A9E6C8500147676 /* CopyFiles */, 70 | ); 71 | buildRules = ( 72 | ); 73 | dependencies = ( 74 | ); 75 | name = RNReactNativeLocationSwitch; 76 | productName = RCTDataManager; 77 | productReference = 134814201AA4EA6300B7C361 /* libRNReactNativeLocationSwitch.a */; 78 | productType = "com.apple.product-type.library.static"; 79 | }; 80 | /* End PBXNativeTarget section */ 81 | 82 | /* Begin PBXProject section */ 83 | 58B511D31A9E6C8500147676 /* Project object */ = { 84 | isa = PBXProject; 85 | attributes = { 86 | LastUpgradeCheck = 0830; 87 | ORGANIZATIONNAME = Facebook; 88 | TargetAttributes = { 89 | 58B511DA1A9E6C8500147676 = { 90 | CreatedOnToolsVersion = 6.1.1; 91 | }; 92 | }; 93 | }; 94 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNReactNativeLocationSwitch" */; 95 | compatibilityVersion = "Xcode 3.2"; 96 | developmentRegion = English; 97 | hasScannedForEncodings = 0; 98 | knownRegions = ( 99 | en, 100 | ); 101 | mainGroup = 58B511D21A9E6C8500147676; 102 | productRefGroup = 58B511D21A9E6C8500147676; 103 | projectDirPath = ""; 104 | projectRoot = ""; 105 | targets = ( 106 | 58B511DA1A9E6C8500147676 /* RNReactNativeLocationSwitch */, 107 | ); 108 | }; 109 | /* End PBXProject section */ 110 | 111 | /* Begin PBXSourcesBuildPhase section */ 112 | 58B511D71A9E6C8500147676 /* Sources */ = { 113 | isa = PBXSourcesBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | B3E7B58A1CC2AC0600A0062D /* RNReactNativeLocationSwitch.m in Sources */, 117 | ); 118 | runOnlyForDeploymentPostprocessing = 0; 119 | }; 120 | /* End PBXSourcesBuildPhase section */ 121 | 122 | /* Begin XCBuildConfiguration section */ 123 | 58B511ED1A9E6C8500147676 /* Debug */ = { 124 | isa = XCBuildConfiguration; 125 | buildSettings = { 126 | ALWAYS_SEARCH_USER_PATHS = NO; 127 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 128 | CLANG_CXX_LIBRARY = "libc++"; 129 | CLANG_ENABLE_MODULES = YES; 130 | CLANG_ENABLE_OBJC_ARC = YES; 131 | CLANG_WARN_BOOL_CONVERSION = YES; 132 | CLANG_WARN_CONSTANT_CONVERSION = YES; 133 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 134 | CLANG_WARN_EMPTY_BODY = YES; 135 | CLANG_WARN_ENUM_CONVERSION = YES; 136 | CLANG_WARN_INFINITE_RECURSION = YES; 137 | CLANG_WARN_INT_CONVERSION = YES; 138 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 139 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 140 | CLANG_WARN_UNREACHABLE_CODE = YES; 141 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 142 | COPY_PHASE_STRIP = NO; 143 | ENABLE_STRICT_OBJC_MSGSEND = YES; 144 | ENABLE_TESTABILITY = YES; 145 | GCC_C_LANGUAGE_STANDARD = gnu99; 146 | GCC_DYNAMIC_NO_PIC = NO; 147 | GCC_NO_COMMON_BLOCKS = YES; 148 | GCC_OPTIMIZATION_LEVEL = 0; 149 | GCC_PREPROCESSOR_DEFINITIONS = ( 150 | "DEBUG=1", 151 | "$(inherited)", 152 | ); 153 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 154 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 155 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 156 | GCC_WARN_UNDECLARED_SELECTOR = YES; 157 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 158 | GCC_WARN_UNUSED_FUNCTION = YES; 159 | GCC_WARN_UNUSED_VARIABLE = YES; 160 | HEADER_SEARCH_PATHS = ( 161 | "$(SRCROOT)/../node_modules/react-native/React/**", 162 | "$(SRCROOT)/../node_modules/react-native/React/Base/**", 163 | ); 164 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 165 | MTL_ENABLE_DEBUG_INFO = YES; 166 | ONLY_ACTIVE_ARCH = YES; 167 | SDKROOT = iphoneos; 168 | }; 169 | name = Debug; 170 | }; 171 | 58B511EE1A9E6C8500147676 /* Release */ = { 172 | isa = XCBuildConfiguration; 173 | buildSettings = { 174 | ALWAYS_SEARCH_USER_PATHS = NO; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_WARN_BOOL_CONVERSION = YES; 180 | CLANG_WARN_CONSTANT_CONVERSION = YES; 181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 182 | CLANG_WARN_EMPTY_BODY = YES; 183 | CLANG_WARN_ENUM_CONVERSION = YES; 184 | CLANG_WARN_INFINITE_RECURSION = YES; 185 | CLANG_WARN_INT_CONVERSION = YES; 186 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 187 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 188 | CLANG_WARN_UNREACHABLE_CODE = YES; 189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 190 | COPY_PHASE_STRIP = YES; 191 | ENABLE_NS_ASSERTIONS = NO; 192 | ENABLE_STRICT_OBJC_MSGSEND = YES; 193 | GCC_C_LANGUAGE_STANDARD = gnu99; 194 | GCC_NO_COMMON_BLOCKS = YES; 195 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 196 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 197 | GCC_WARN_UNDECLARED_SELECTOR = YES; 198 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 199 | GCC_WARN_UNUSED_FUNCTION = YES; 200 | GCC_WARN_UNUSED_VARIABLE = YES; 201 | HEADER_SEARCH_PATHS = ( 202 | "$(SRCROOT)/../node_modules/react-native/React/**", 203 | "$(SRCROOT)/../node_modules/react-native/React/Base/**", 204 | ); 205 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 206 | MTL_ENABLE_DEBUG_INFO = NO; 207 | SDKROOT = iphoneos; 208 | VALIDATE_PRODUCT = YES; 209 | }; 210 | name = Release; 211 | }; 212 | 58B511F01A9E6C8500147676 /* Debug */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | HEADER_SEARCH_PATHS = ( 216 | "$(inherited)", 217 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 218 | "$(SRCROOT)/../../../React/**", 219 | "$(SRCROOT)/../../react-native/React/**", 220 | ); 221 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 222 | OTHER_LDFLAGS = "-ObjC"; 223 | PRODUCT_NAME = RNReactNativeLocationSwitch; 224 | SKIP_INSTALL = YES; 225 | }; 226 | name = Debug; 227 | }; 228 | 58B511F11A9E6C8500147676 /* Release */ = { 229 | isa = XCBuildConfiguration; 230 | buildSettings = { 231 | HEADER_SEARCH_PATHS = ( 232 | "$(inherited)", 233 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 234 | "$(SRCROOT)/../../../React/**", 235 | "$(SRCROOT)/../../react-native/React/**", 236 | ); 237 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 238 | OTHER_LDFLAGS = "-ObjC"; 239 | PRODUCT_NAME = RNReactNativeLocationSwitch; 240 | SKIP_INSTALL = YES; 241 | }; 242 | name = Release; 243 | }; 244 | /* End XCBuildConfiguration section */ 245 | 246 | /* Begin XCConfigurationList section */ 247 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNReactNativeLocationSwitch" */ = { 248 | isa = XCConfigurationList; 249 | buildConfigurations = ( 250 | 58B511ED1A9E6C8500147676 /* Debug */, 251 | 58B511EE1A9E6C8500147676 /* Release */, 252 | ); 253 | defaultConfigurationIsVisible = 0; 254 | defaultConfigurationName = Release; 255 | }; 256 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNReactNativeLocationSwitch" */ = { 257 | isa = XCConfigurationList; 258 | buildConfigurations = ( 259 | 58B511F01A9E6C8500147676 /* Debug */, 260 | 58B511F11A9E6C8500147676 /* Release */, 261 | ); 262 | defaultConfigurationIsVisible = 0; 263 | defaultConfigurationName = Release; 264 | }; 265 | /* End XCConfigurationList section */ 266 | }; 267 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 268 | } 269 | -------------------------------------------------------------------------------- /ios/ReactNativeAndroidLocationSwitch.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "ReactNativeAndroidLocationSwitch" 4 | s.version = "1.0.0" 5 | s.summary = "ReactNativeAndroidLocationSwitch" 6 | s.description = <<-DESC 7 | ReactNativeAndroidLocationSwitch 8 | DESC 9 | s.homepage = "" 10 | s.license = "Apache-2.0" 11 | # s.license = { :type => "Apache-2.0", :file => "../LICENSE" } 12 | s.author = { "author" => "author@domain.cn" } 13 | s.platform = :ios, "7.0" 14 | s.source = { :git => "https://github.com/philiWeitz/react-native-android-location-switch.git", :tag => "master" } 15 | s.source_files = "ReactNativeAndroidLocationSwitch/**/*.{h,m}" 16 | s.requires_arc = true 17 | 18 | 19 | s.dependency "React" 20 | #s.dependency "others" 21 | 22 | end 23 | 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-location-switch", 3 | "version": "0.1.0", 4 | "author": "Philipp Weitz", 5 | "private": false, 6 | "license": "Apache-2.0", 7 | "nativePackage": true, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/philiWeitz/react-native-location-switch.git" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/philiWeitz/react-native-location-switch/issues" 14 | }, 15 | "keywords": [ 16 | "react-native", 17 | "android", 18 | "ios", 19 | "library", 20 | "location" 21 | ], 22 | "peerDependencies": { 23 | "react-native": ">= 0.38.0" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /preview/previewAndroid.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiWeitz/react-native-location-switch/835f37bffac46b221c7a372069699b304fb4ccb4/preview/previewAndroid.gif -------------------------------------------------------------------------------- /preview/previewIOS.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiWeitz/react-native-location-switch/835f37bffac46b221c7a372069699b304fb4ccb4/preview/previewIOS.gif --------------------------------------------------------------------------------