├── .gitignore ├── Example └── MotionExample │ ├── MotionManager.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ └── MotionManager.xcscheme │ ├── README.md │ ├── components │ ├── AccelerometerManager.js │ ├── GyroscopeManager.js │ └── Magnetometer.js │ ├── iOS │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ └── LaunchScreen.xib │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── main.jsbundle │ └── main.m │ ├── index.ios.js │ └── package.json ├── README.md ├── RNMotionManager.xcodeproj └── project.pbxproj ├── RNMotionManager ├── Accelerometer.h ├── Accelerometer.m ├── Gyroscope.h ├── Gyroscope.m ├── Magnetometer.h └── Magnetometer.m ├── RNMotionManagerTests └── Info.plist ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | !**/*.xcodeproj 3 | !**/*.pbxproj 4 | !**/*.xcworkspacedata 5 | !**/*.xcsettings 6 | !**/*.xcscheme 7 | *.xcworkspace 8 | 9 | build/ 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | *.xccheckout 20 | *.moved-aside 21 | DerivedData 22 | *.hmap 23 | *.ipa 24 | *.xcuserstate 25 | profile 26 | .idea/ 27 | Pods 28 | 29 | # OS X 30 | .DS_Store 31 | 32 | # Node 33 | node_modules -------------------------------------------------------------------------------- /Example/MotionExample/MotionManager.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 00481BE81AC0C86700671115 /* libRCTWebSocketDebugger.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */; }; 11 | 008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; }; 12 | 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 13 | 00C302E61ABCBA2D00DB3ED1 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302B41ABCB8E700DB3ED1 /* libRCTAdSupport.a */; }; 14 | 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; 15 | 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */; }; 16 | 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */; }; 17 | 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */; }; 18 | 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 78C398B91ACF4ADC00677621 /* libRCTLinking.a */; }; 19 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 20 | 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 21 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 22 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 23 | 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; 24 | 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; 25 | BB9CC8371AE0AA7B008A1D08 /* libRNMotionManager.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BB9CC8341AE0AA72008A1D08 /* libRNMotionManager.a */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXContainerItemProxy section */ 29 | 00481BE51AC0C7FA00671115 /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */; 32 | proxyType = 2; 33 | remoteGlobalIDString = 832C81801AAF6DEF007FA2F7; 34 | remoteInfo = RCTWebSocketDebugger; 35 | }; 36 | 00C302AB1ABCB8CE00DB3ED1 /* PBXContainerItemProxy */ = { 37 | isa = PBXContainerItemProxy; 38 | containerPortal = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; 39 | proxyType = 2; 40 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 41 | remoteInfo = RCTActionSheet; 42 | }; 43 | 00C302B31ABCB8E700DB3ED1 /* PBXContainerItemProxy */ = { 44 | isa = PBXContainerItemProxy; 45 | containerPortal = 00C302AF1ABCB8E700DB3ED1 /* RCTAdSupport.xcodeproj */; 46 | proxyType = 2; 47 | remoteGlobalIDString = 832C81801AAF6DEF007FA2F7; 48 | remoteInfo = RCTAdSupport; 49 | }; 50 | 00C302B91ABCB90400DB3ED1 /* PBXContainerItemProxy */ = { 51 | isa = PBXContainerItemProxy; 52 | containerPortal = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; 53 | proxyType = 2; 54 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 55 | remoteInfo = RCTGeolocation; 56 | }; 57 | 00C302BF1ABCB91800DB3ED1 /* PBXContainerItemProxy */ = { 58 | isa = PBXContainerItemProxy; 59 | containerPortal = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */; 60 | proxyType = 2; 61 | remoteGlobalIDString = 58B5115D1A9E6B3D00147676; 62 | remoteInfo = RCTImage; 63 | }; 64 | 00C302DB1ABCB9D200DB3ED1 /* PBXContainerItemProxy */ = { 65 | isa = PBXContainerItemProxy; 66 | containerPortal = 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */; 67 | proxyType = 2; 68 | remoteGlobalIDString = 58B511DB1A9E6C8500147676; 69 | remoteInfo = RCTNetwork; 70 | }; 71 | 00C302E31ABCB9EE00DB3ED1 /* PBXContainerItemProxy */ = { 72 | isa = PBXContainerItemProxy; 73 | containerPortal = 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */; 74 | proxyType = 2; 75 | remoteGlobalIDString = 832C81801AAF6DEF007FA2F7; 76 | remoteInfo = RCTVibration; 77 | }; 78 | 146834031AC3E56700842450 /* PBXContainerItemProxy */ = { 79 | isa = PBXContainerItemProxy; 80 | containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; 81 | proxyType = 2; 82 | remoteGlobalIDString = 83CBBA2E1A601D0E00E9B192; 83 | remoteInfo = React; 84 | }; 85 | 78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */ = { 86 | isa = PBXContainerItemProxy; 87 | containerPortal = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */; 88 | proxyType = 2; 89 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 90 | remoteInfo = RCTLinking; 91 | }; 92 | 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */ = { 93 | isa = PBXContainerItemProxy; 94 | containerPortal = 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */; 95 | proxyType = 2; 96 | remoteGlobalIDString = 58B5119B1A9E6C1200147676; 97 | remoteInfo = RCTText; 98 | }; 99 | BB9CC8331AE0AA72008A1D08 /* PBXContainerItemProxy */ = { 100 | isa = PBXContainerItemProxy; 101 | containerPortal = BB9CC8241AE0AA72008A1D08 /* RNMotionManager.xcodeproj */; 102 | proxyType = 2; 103 | remoteGlobalIDString = BB9CC7ED1AE0A2EB008A1D08; 104 | remoteInfo = RNMotionManager; 105 | }; 106 | BB9CC8351AE0AA72008A1D08 /* PBXContainerItemProxy */ = { 107 | isa = PBXContainerItemProxy; 108 | containerPortal = BB9CC8241AE0AA72008A1D08 /* RNMotionManager.xcodeproj */; 109 | proxyType = 2; 110 | remoteGlobalIDString = BB9CC7F81AE0A2EB008A1D08; 111 | remoteInfo = RNMotionManagerTests; 112 | }; 113 | /* End PBXContainerItemProxy section */ 114 | 115 | /* Begin PBXFileReference section */ 116 | 00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocketDebugger.xcodeproj; path = "node_modules/react-native/Libraries/RCTWebSocketDebugger/RCTWebSocketDebugger.xcodeproj"; sourceTree = ""; }; 117 | 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = ""; }; 118 | 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = "node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj"; sourceTree = ""; }; 119 | 00C302AF1ABCB8E700DB3ED1 /* RCTAdSupport.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAdSupport.xcodeproj; path = "node_modules/react-native/Libraries/AdSupport/RCTAdSupport.xcodeproj"; sourceTree = ""; }; 120 | 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = "node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj"; sourceTree = ""; }; 121 | 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = ""; }; 122 | 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = ""; }; 123 | 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = ""; }; 124 | 13B07F961A680F5B00A75B9A /* MotionManager.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MotionManager.app; sourceTree = BUILT_PRODUCTS_DIR; }; 125 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = iOS/AppDelegate.h; sourceTree = ""; }; 126 | 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = iOS/AppDelegate.m; sourceTree = ""; }; 127 | 13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 128 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = iOS/Images.xcassets; sourceTree = ""; }; 129 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = iOS/Info.plist; sourceTree = ""; }; 130 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = iOS/main.m; sourceTree = ""; }; 131 | 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; 132 | 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = ""; }; 133 | 7FA2E0D61ADAF3B100BC59C0 /* Accelerometer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Accelerometer.h; path = iOS/Accelerometer.h; sourceTree = ""; }; 134 | 7FA2E0D71ADAF3B100BC59C0 /* Accelerometer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Accelerometer.m; path = iOS/Accelerometer.m; sourceTree = ""; }; 135 | 7FA2E0E31ADAFADA00BC59C0 /* Magnetometer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Magnetometer.h; path = iOS/Magnetometer.h; sourceTree = ""; }; 136 | 7FA2E0E41ADAFADA00BC59C0 /* Magnetometer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Magnetometer.m; path = iOS/Magnetometer.m; sourceTree = ""; }; 137 | 7FBF246F1AD98B10006F2112 /* Gyroscope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Gyroscope.h; path = iOS/Gyroscope.h; sourceTree = ""; }; 138 | 7FBF24701AD98B10006F2112 /* Gyroscope.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Gyroscope.m; path = iOS/Gyroscope.m; sourceTree = ""; }; 139 | 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = ""; }; 140 | BB9CC8241AE0AA72008A1D08 /* RNMotionManager.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNMotionManager.xcodeproj; path = "node_modules/react-native-motion-manager/RNMotionManager.xcodeproj"; sourceTree = ""; }; 141 | /* End PBXFileReference section */ 142 | 143 | /* Begin PBXFrameworksBuildPhase section */ 144 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { 145 | isa = PBXFrameworksBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | BB9CC8371AE0AA7B008A1D08 /* libRNMotionManager.a in Frameworks */, 149 | 146834051AC3E58100842450 /* libReact.a in Frameworks */, 150 | 00481BE81AC0C86700671115 /* libRCTWebSocketDebugger.a in Frameworks */, 151 | 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, 152 | 00C302E61ABCBA2D00DB3ED1 /* libRCTAdSupport.a in Frameworks */, 153 | 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */, 154 | 00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */, 155 | 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */, 156 | 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */, 157 | 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 158 | 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */, 159 | ); 160 | runOnlyForDeploymentPostprocessing = 0; 161 | }; 162 | /* End PBXFrameworksBuildPhase section */ 163 | 164 | /* Begin PBXGroup section */ 165 | 00481BDC1AC0C7FA00671115 /* Products */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */, 169 | ); 170 | name = Products; 171 | sourceTree = ""; 172 | }; 173 | 00C302A81ABCB8CE00DB3ED1 /* Products */ = { 174 | isa = PBXGroup; 175 | children = ( 176 | 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */, 177 | ); 178 | name = Products; 179 | sourceTree = ""; 180 | }; 181 | 00C302B01ABCB8E700DB3ED1 /* Products */ = { 182 | isa = PBXGroup; 183 | children = ( 184 | 00C302B41ABCB8E700DB3ED1 /* libRCTAdSupport.a */, 185 | ); 186 | name = Products; 187 | sourceTree = ""; 188 | }; 189 | 00C302B61ABCB90400DB3ED1 /* Products */ = { 190 | isa = PBXGroup; 191 | children = ( 192 | 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */, 193 | ); 194 | name = Products; 195 | sourceTree = ""; 196 | }; 197 | 00C302BC1ABCB91800DB3ED1 /* Products */ = { 198 | isa = PBXGroup; 199 | children = ( 200 | 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */, 201 | ); 202 | name = Products; 203 | sourceTree = ""; 204 | }; 205 | 00C302D41ABCB9D200DB3ED1 /* Products */ = { 206 | isa = PBXGroup; 207 | children = ( 208 | 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */, 209 | ); 210 | name = Products; 211 | sourceTree = ""; 212 | }; 213 | 00C302E01ABCB9EE00DB3ED1 /* Products */ = { 214 | isa = PBXGroup; 215 | children = ( 216 | 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */, 217 | ); 218 | name = Products; 219 | sourceTree = ""; 220 | }; 221 | 13B07FAE1A68108700A75B9A /* MotionManager */ = { 222 | isa = PBXGroup; 223 | children = ( 224 | 7FBF246F1AD98B10006F2112 /* Gyroscope.h */, 225 | 7FBF24701AD98B10006F2112 /* Gyroscope.m */, 226 | 008F07F21AC5B25A0029DE68 /* main.jsbundle */, 227 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 228 | 13B07FB01A68108700A75B9A /* AppDelegate.m */, 229 | 13B07FB51A68108700A75B9A /* Images.xcassets */, 230 | 13B07FB61A68108700A75B9A /* Info.plist */, 231 | 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, 232 | 13B07FB71A68108700A75B9A /* main.m */, 233 | 7FA2E0D61ADAF3B100BC59C0 /* Accelerometer.h */, 234 | 7FA2E0D71ADAF3B100BC59C0 /* Accelerometer.m */, 235 | 7FA2E0E31ADAFADA00BC59C0 /* Magnetometer.h */, 236 | 7FA2E0E41ADAFADA00BC59C0 /* Magnetometer.m */, 237 | ); 238 | name = MotionManager; 239 | sourceTree = ""; 240 | }; 241 | 146834001AC3E56700842450 /* Products */ = { 242 | isa = PBXGroup; 243 | children = ( 244 | 146834041AC3E56700842450 /* libReact.a */, 245 | ); 246 | name = Products; 247 | sourceTree = ""; 248 | }; 249 | 78C398B11ACF4ADC00677621 /* Products */ = { 250 | isa = PBXGroup; 251 | children = ( 252 | 78C398B91ACF4ADC00677621 /* libRCTLinking.a */, 253 | ); 254 | name = Products; 255 | sourceTree = ""; 256 | }; 257 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = { 258 | isa = PBXGroup; 259 | children = ( 260 | 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */, 261 | 146833FF1AC3E56700842450 /* React.xcodeproj */, 262 | 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */, 263 | 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */, 264 | 00C302AF1ABCB8E700DB3ED1 /* RCTAdSupport.xcodeproj */, 265 | 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */, 266 | 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */, 267 | 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */, 268 | 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */, 269 | 00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */, 270 | ); 271 | name = Libraries; 272 | sourceTree = ""; 273 | }; 274 | 832341B11AAA6A8300B99B32 /* Products */ = { 275 | isa = PBXGroup; 276 | children = ( 277 | 832341B51AAA6A8300B99B32 /* libRCTText.a */, 278 | ); 279 | name = Products; 280 | sourceTree = ""; 281 | }; 282 | 83CBB9F61A601CBA00E9B192 = { 283 | isa = PBXGroup; 284 | children = ( 285 | BB9CC8241AE0AA72008A1D08 /* RNMotionManager.xcodeproj */, 286 | 13B07FAE1A68108700A75B9A /* MotionManager */, 287 | 832341AE1AAA6A7D00B99B32 /* Libraries */, 288 | 83CBBA001A601CBA00E9B192 /* Products */, 289 | ); 290 | indentWidth = 2; 291 | sourceTree = ""; 292 | tabWidth = 2; 293 | }; 294 | 83CBBA001A601CBA00E9B192 /* Products */ = { 295 | isa = PBXGroup; 296 | children = ( 297 | 13B07F961A680F5B00A75B9A /* MotionManager.app */, 298 | ); 299 | name = Products; 300 | sourceTree = ""; 301 | }; 302 | BB9CC8251AE0AA72008A1D08 /* Products */ = { 303 | isa = PBXGroup; 304 | children = ( 305 | BB9CC8341AE0AA72008A1D08 /* libRNMotionManager.a */, 306 | BB9CC8361AE0AA72008A1D08 /* RNMotionManagerTests.xctest */, 307 | ); 308 | name = Products; 309 | sourceTree = ""; 310 | }; 311 | /* End PBXGroup section */ 312 | 313 | /* Begin PBXNativeTarget section */ 314 | 13B07F861A680F5B00A75B9A /* MotionManager */ = { 315 | isa = PBXNativeTarget; 316 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "MotionManager" */; 317 | buildPhases = ( 318 | 13B07F871A680F5B00A75B9A /* Sources */, 319 | 13B07F8C1A680F5B00A75B9A /* Frameworks */, 320 | 13B07F8E1A680F5B00A75B9A /* Resources */, 321 | ); 322 | buildRules = ( 323 | ); 324 | dependencies = ( 325 | ); 326 | name = MotionManager; 327 | productName = "Hello World"; 328 | productReference = 13B07F961A680F5B00A75B9A /* MotionManager.app */; 329 | productType = "com.apple.product-type.application"; 330 | }; 331 | /* End PBXNativeTarget section */ 332 | 333 | /* Begin PBXProject section */ 334 | 83CBB9F71A601CBA00E9B192 /* Project object */ = { 335 | isa = PBXProject; 336 | attributes = { 337 | LastUpgradeCheck = 0610; 338 | ORGANIZATIONNAME = Facebook; 339 | }; 340 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "MotionManager" */; 341 | compatibilityVersion = "Xcode 3.2"; 342 | developmentRegion = English; 343 | hasScannedForEncodings = 0; 344 | knownRegions = ( 345 | en, 346 | Base, 347 | ); 348 | mainGroup = 83CBB9F61A601CBA00E9B192; 349 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; 350 | projectDirPath = ""; 351 | projectReferences = ( 352 | { 353 | ProductGroup = 00C302A81ABCB8CE00DB3ED1 /* Products */; 354 | ProjectRef = 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */; 355 | }, 356 | { 357 | ProductGroup = 00C302B01ABCB8E700DB3ED1 /* Products */; 358 | ProjectRef = 00C302AF1ABCB8E700DB3ED1 /* RCTAdSupport.xcodeproj */; 359 | }, 360 | { 361 | ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */; 362 | ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; 363 | }, 364 | { 365 | ProductGroup = 00C302BC1ABCB91800DB3ED1 /* Products */; 366 | ProjectRef = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */; 367 | }, 368 | { 369 | ProductGroup = 78C398B11ACF4ADC00677621 /* Products */; 370 | ProjectRef = 78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */; 371 | }, 372 | { 373 | ProductGroup = 00C302D41ABCB9D200DB3ED1 /* Products */; 374 | ProjectRef = 00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */; 375 | }, 376 | { 377 | ProductGroup = 832341B11AAA6A8300B99B32 /* Products */; 378 | ProjectRef = 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */; 379 | }, 380 | { 381 | ProductGroup = 00C302E01ABCB9EE00DB3ED1 /* Products */; 382 | ProjectRef = 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */; 383 | }, 384 | { 385 | ProductGroup = 00481BDC1AC0C7FA00671115 /* Products */; 386 | ProjectRef = 00481BDB1AC0C7FA00671115 /* RCTWebSocketDebugger.xcodeproj */; 387 | }, 388 | { 389 | ProductGroup = 146834001AC3E56700842450 /* Products */; 390 | ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */; 391 | }, 392 | { 393 | ProductGroup = BB9CC8251AE0AA72008A1D08 /* Products */; 394 | ProjectRef = BB9CC8241AE0AA72008A1D08 /* RNMotionManager.xcodeproj */; 395 | }, 396 | ); 397 | projectRoot = ""; 398 | targets = ( 399 | 13B07F861A680F5B00A75B9A /* MotionManager */, 400 | ); 401 | }; 402 | /* End PBXProject section */ 403 | 404 | /* Begin PBXReferenceProxy section */ 405 | 00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */ = { 406 | isa = PBXReferenceProxy; 407 | fileType = archive.ar; 408 | path = libRCTWebSocketDebugger.a; 409 | remoteRef = 00481BE51AC0C7FA00671115 /* PBXContainerItemProxy */; 410 | sourceTree = BUILT_PRODUCTS_DIR; 411 | }; 412 | 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */ = { 413 | isa = PBXReferenceProxy; 414 | fileType = archive.ar; 415 | path = libRCTActionSheet.a; 416 | remoteRef = 00C302AB1ABCB8CE00DB3ED1 /* PBXContainerItemProxy */; 417 | sourceTree = BUILT_PRODUCTS_DIR; 418 | }; 419 | 00C302B41ABCB8E700DB3ED1 /* libRCTAdSupport.a */ = { 420 | isa = PBXReferenceProxy; 421 | fileType = archive.ar; 422 | path = libRCTAdSupport.a; 423 | remoteRef = 00C302B31ABCB8E700DB3ED1 /* PBXContainerItemProxy */; 424 | sourceTree = BUILT_PRODUCTS_DIR; 425 | }; 426 | 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */ = { 427 | isa = PBXReferenceProxy; 428 | fileType = archive.ar; 429 | path = libRCTGeolocation.a; 430 | remoteRef = 00C302B91ABCB90400DB3ED1 /* PBXContainerItemProxy */; 431 | sourceTree = BUILT_PRODUCTS_DIR; 432 | }; 433 | 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */ = { 434 | isa = PBXReferenceProxy; 435 | fileType = archive.ar; 436 | path = libRCTImage.a; 437 | remoteRef = 00C302BF1ABCB91800DB3ED1 /* PBXContainerItemProxy */; 438 | sourceTree = BUILT_PRODUCTS_DIR; 439 | }; 440 | 00C302DC1ABCB9D200DB3ED1 /* libRCTNetwork.a */ = { 441 | isa = PBXReferenceProxy; 442 | fileType = archive.ar; 443 | path = libRCTNetwork.a; 444 | remoteRef = 00C302DB1ABCB9D200DB3ED1 /* PBXContainerItemProxy */; 445 | sourceTree = BUILT_PRODUCTS_DIR; 446 | }; 447 | 00C302E41ABCB9EE00DB3ED1 /* libRCTVibration.a */ = { 448 | isa = PBXReferenceProxy; 449 | fileType = archive.ar; 450 | path = libRCTVibration.a; 451 | remoteRef = 00C302E31ABCB9EE00DB3ED1 /* PBXContainerItemProxy */; 452 | sourceTree = BUILT_PRODUCTS_DIR; 453 | }; 454 | 146834041AC3E56700842450 /* libReact.a */ = { 455 | isa = PBXReferenceProxy; 456 | fileType = archive.ar; 457 | path = libReact.a; 458 | remoteRef = 146834031AC3E56700842450 /* PBXContainerItemProxy */; 459 | sourceTree = BUILT_PRODUCTS_DIR; 460 | }; 461 | 78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = { 462 | isa = PBXReferenceProxy; 463 | fileType = archive.ar; 464 | path = libRCTLinking.a; 465 | remoteRef = 78C398B81ACF4ADC00677621 /* PBXContainerItemProxy */; 466 | sourceTree = BUILT_PRODUCTS_DIR; 467 | }; 468 | 832341B51AAA6A8300B99B32 /* libRCTText.a */ = { 469 | isa = PBXReferenceProxy; 470 | fileType = archive.ar; 471 | path = libRCTText.a; 472 | remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */; 473 | sourceTree = BUILT_PRODUCTS_DIR; 474 | }; 475 | BB9CC8341AE0AA72008A1D08 /* libRNMotionManager.a */ = { 476 | isa = PBXReferenceProxy; 477 | fileType = archive.ar; 478 | path = libRNMotionManager.a; 479 | remoteRef = BB9CC8331AE0AA72008A1D08 /* PBXContainerItemProxy */; 480 | sourceTree = BUILT_PRODUCTS_DIR; 481 | }; 482 | BB9CC8361AE0AA72008A1D08 /* RNMotionManagerTests.xctest */ = { 483 | isa = PBXReferenceProxy; 484 | fileType = wrapper.cfbundle; 485 | path = RNMotionManagerTests.xctest; 486 | remoteRef = BB9CC8351AE0AA72008A1D08 /* PBXContainerItemProxy */; 487 | sourceTree = BUILT_PRODUCTS_DIR; 488 | }; 489 | /* End PBXReferenceProxy section */ 490 | 491 | /* Begin PBXResourcesBuildPhase section */ 492 | 13B07F8E1A680F5B00A75B9A /* Resources */ = { 493 | isa = PBXResourcesBuildPhase; 494 | buildActionMask = 2147483647; 495 | files = ( 496 | 008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */, 497 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 498 | 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, 499 | ); 500 | runOnlyForDeploymentPostprocessing = 0; 501 | }; 502 | /* End PBXResourcesBuildPhase section */ 503 | 504 | /* Begin PBXSourcesBuildPhase section */ 505 | 13B07F871A680F5B00A75B9A /* Sources */ = { 506 | isa = PBXSourcesBuildPhase; 507 | buildActionMask = 2147483647; 508 | files = ( 509 | 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, 510 | 13B07FC11A68108700A75B9A /* main.m in Sources */, 511 | ); 512 | runOnlyForDeploymentPostprocessing = 0; 513 | }; 514 | /* End PBXSourcesBuildPhase section */ 515 | 516 | /* Begin PBXVariantGroup section */ 517 | 13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = { 518 | isa = PBXVariantGroup; 519 | children = ( 520 | 13B07FB21A68108700A75B9A /* Base */, 521 | ); 522 | name = LaunchScreen.xib; 523 | path = iOS; 524 | sourceTree = ""; 525 | }; 526 | /* End PBXVariantGroup section */ 527 | 528 | /* Begin XCBuildConfiguration section */ 529 | 13B07F941A680F5B00A75B9A /* Debug */ = { 530 | isa = XCBuildConfiguration; 531 | buildSettings = { 532 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 533 | HEADER_SEARCH_PATHS = ( 534 | "$(inherited)", 535 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 536 | "$(SRCROOT)/node_modules/react-native/React/**", 537 | ); 538 | INFOPLIST_FILE = "$(SRCROOT)/iOS/Info.plist"; 539 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 540 | OTHER_LDFLAGS = "-ObjC"; 541 | PRODUCT_NAME = MotionManager; 542 | }; 543 | name = Debug; 544 | }; 545 | 13B07F951A680F5B00A75B9A /* Release */ = { 546 | isa = XCBuildConfiguration; 547 | buildSettings = { 548 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 549 | HEADER_SEARCH_PATHS = ( 550 | "$(inherited)", 551 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 552 | "$(SRCROOT)/node_modules/react-native/React/**", 553 | ); 554 | INFOPLIST_FILE = "$(SRCROOT)/iOS/Info.plist"; 555 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 556 | OTHER_LDFLAGS = "-ObjC"; 557 | PRODUCT_NAME = MotionManager; 558 | }; 559 | name = Release; 560 | }; 561 | 83CBBA201A601CBA00E9B192 /* Debug */ = { 562 | isa = XCBuildConfiguration; 563 | buildSettings = { 564 | ALWAYS_SEARCH_USER_PATHS = NO; 565 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 566 | CLANG_CXX_LIBRARY = "libc++"; 567 | CLANG_ENABLE_MODULES = YES; 568 | CLANG_ENABLE_OBJC_ARC = YES; 569 | CLANG_WARN_BOOL_CONVERSION = YES; 570 | CLANG_WARN_CONSTANT_CONVERSION = YES; 571 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 572 | CLANG_WARN_EMPTY_BODY = YES; 573 | CLANG_WARN_ENUM_CONVERSION = YES; 574 | CLANG_WARN_INT_CONVERSION = YES; 575 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 576 | CLANG_WARN_UNREACHABLE_CODE = YES; 577 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 578 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 579 | COPY_PHASE_STRIP = NO; 580 | ENABLE_STRICT_OBJC_MSGSEND = YES; 581 | GCC_C_LANGUAGE_STANDARD = gnu99; 582 | GCC_DYNAMIC_NO_PIC = NO; 583 | GCC_OPTIMIZATION_LEVEL = 0; 584 | GCC_PREPROCESSOR_DEFINITIONS = ( 585 | "DEBUG=1", 586 | "$(inherited)", 587 | ); 588 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 589 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 590 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 591 | GCC_WARN_UNDECLARED_SELECTOR = YES; 592 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 593 | GCC_WARN_UNUSED_FUNCTION = YES; 594 | GCC_WARN_UNUSED_VARIABLE = YES; 595 | HEADER_SEARCH_PATHS = ( 596 | "$(inherited)", 597 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 598 | "$(SRCROOT)/node_modules/react-native/React/**", 599 | ); 600 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 601 | MTL_ENABLE_DEBUG_INFO = YES; 602 | ONLY_ACTIVE_ARCH = YES; 603 | SDKROOT = iphoneos; 604 | }; 605 | name = Debug; 606 | }; 607 | 83CBBA211A601CBA00E9B192 /* Release */ = { 608 | isa = XCBuildConfiguration; 609 | buildSettings = { 610 | ALWAYS_SEARCH_USER_PATHS = NO; 611 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 612 | CLANG_CXX_LIBRARY = "libc++"; 613 | CLANG_ENABLE_MODULES = YES; 614 | CLANG_ENABLE_OBJC_ARC = YES; 615 | CLANG_WARN_BOOL_CONVERSION = YES; 616 | CLANG_WARN_CONSTANT_CONVERSION = YES; 617 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 618 | CLANG_WARN_EMPTY_BODY = YES; 619 | CLANG_WARN_ENUM_CONVERSION = YES; 620 | CLANG_WARN_INT_CONVERSION = YES; 621 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 622 | CLANG_WARN_UNREACHABLE_CODE = YES; 623 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 624 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 625 | COPY_PHASE_STRIP = YES; 626 | ENABLE_NS_ASSERTIONS = NO; 627 | ENABLE_STRICT_OBJC_MSGSEND = YES; 628 | GCC_C_LANGUAGE_STANDARD = gnu99; 629 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 630 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 631 | GCC_WARN_UNDECLARED_SELECTOR = YES; 632 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 633 | GCC_WARN_UNUSED_FUNCTION = YES; 634 | GCC_WARN_UNUSED_VARIABLE = YES; 635 | HEADER_SEARCH_PATHS = ( 636 | "$(inherited)", 637 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 638 | "$(SRCROOT)/node_modules/react-native/React/**", 639 | ); 640 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 641 | MTL_ENABLE_DEBUG_INFO = NO; 642 | SDKROOT = iphoneos; 643 | VALIDATE_PRODUCT = YES; 644 | }; 645 | name = Release; 646 | }; 647 | /* End XCBuildConfiguration section */ 648 | 649 | /* Begin XCConfigurationList section */ 650 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "MotionManager" */ = { 651 | isa = XCConfigurationList; 652 | buildConfigurations = ( 653 | 13B07F941A680F5B00A75B9A /* Debug */, 654 | 13B07F951A680F5B00A75B9A /* Release */, 655 | ); 656 | defaultConfigurationIsVisible = 0; 657 | defaultConfigurationName = Release; 658 | }; 659 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "MotionManager" */ = { 660 | isa = XCConfigurationList; 661 | buildConfigurations = ( 662 | 83CBBA201A601CBA00E9B192 /* Debug */, 663 | 83CBBA211A601CBA00E9B192 /* Release */, 664 | ); 665 | defaultConfigurationIsVisible = 0; 666 | defaultConfigurationName = Release; 667 | }; 668 | /* End XCConfigurationList section */ 669 | }; 670 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; 671 | } 672 | -------------------------------------------------------------------------------- /Example/MotionExample/MotionManager.xcodeproj/xcshareddata/xcschemes/MotionManager.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Example/MotionExample/README.md: -------------------------------------------------------------------------------- 1 | # react-native-motion-manager 2 | 3 | # MotionManager 4 | This is a react app that shows how to write obj-c wrappers around the iOS [CMMotionManager](https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMMotionManager_Class/) 5 | library. 6 | # Usage 7 | 8 | If you just want to see this code in action, checkout the code and fire up the xcodeproj and run it. 9 | 10 | If you're trying to integrate this into your app, its a little bit tricky. I don't quite know how to package this up so you can just `npm install` it. Coming soon though! 11 | 12 | At this point, just copy and paste `iOS/Accelerometer.h` + `iOS/Accelerometer.m` (or Gyroscope or Magnetomer) into your `iOS` folder. 13 | 14 | 15 | Does anyone know how to share react-native components that are wrappers around native utilities? 16 | There must be a better way to package this stuff... 17 | 18 | # Api 19 | 20 | ### Setup 21 | ```js 22 | var { 23 | Accelerometer, 24 | Gyroscope, 25 | Magnetometer 26 | } = require('NativeModules'); 27 | var { 28 | DeviceEventEmitter // will emit events that you can listen to 29 | } = React; 30 | ``` 31 | 32 | 33 | ### Accelerometer 34 | ```js 35 | Accelerometer.setAccelerometerUpdateInterval(0.1); // in seconds 36 | DeviceEventEmitter.addListener('AccelerationData', function (data) { 37 | /** 38 | * data.acceleration.x 39 | * data.acceleration.y 40 | * data.acceleration.z 41 | **/ 42 | }); 43 | Accelerometer.startAccelerometerUpdates(); // you'll start getting AccelerationData events above 44 | Accelerometer.stopAccelerometerUpdates(); 45 | ``` 46 | 47 | ### Gyroscope 48 | ```js 49 | Gyroscope.setGyroUpdateInterval(0.1); // in seconds 50 | DeviceEventEmitter.addListener('GyroData', function (data) { 51 | /** 52 | * data.rotationRate.x 53 | * data.rotationRate.y 54 | * data.rotationRate.z 55 | **/ 56 | }); 57 | Gyroscope.startGyroUpdates(); // you'll start getting AccelerationData events above 58 | Gyroscope.stopGyroUpdates(); 59 | ``` 60 | 61 | ### Magnetomer 62 | ```js 63 | Magnetometer.setAccelerometerUpdateInterval(0.1); // in seconds 64 | DeviceEventEmitter.addListener('MagnetometerData', function (data) { 65 | /** 66 | * data.magneticField.x 67 | * data.magneticField.y 68 | * data.magneticField.z 69 | **/ 70 | }); 71 | Magnetometer.startMagnetometerUpdates(); // you'll start getting AccelerationData events above 72 | Magnetometer.stopMagnetometerUpdates(); 73 | ``` 74 | 75 | # Screenshots 76 | 77 | ![](http://pwmckenna.com/react-native-motion-manager/motion.png) 78 | ![](http://pwmckenna.com/react-native-motion-manager/accelerometer.png) 79 | ![](http://pwmckenna.com/react-native-motion-manager/gyroscope.png) 80 | ![](http://pwmckenna.com/react-native-motion-manager/magnetometer.png) 81 | -------------------------------------------------------------------------------- /Example/MotionExample/components/AccelerometerManager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * AccelerometerManager 3 | * 4 | * Created by Patrick Williams in beautiful Seattle, WA. 5 | */ 6 | 'use strict'; 7 | 8 | var React = require('react-native'); 9 | var Button = require('react-native-button'); 10 | var { 11 | Text, 12 | View, 13 | DeviceEventEmitter 14 | } = React; 15 | 16 | var { 17 | Accelerometer 18 | } = require('NativeModules'); 19 | 20 | 21 | Accelerometer.setAccelerometerUpdateInterval(0.1); 22 | 23 | var AccelerometerManager = React.createClass({ 24 | getInitialState: function () { 25 | return { 26 | x: 0, 27 | y: 0, 28 | z: 0, 29 | gyro: false 30 | } 31 | }, 32 | componentDidMount: function () { 33 | DeviceEventEmitter.addListener('AccelerationData', function (data) { 34 | this.setState({ 35 | x: data.acceleration.x.toFixed(5), 36 | y: data.acceleration.y.toFixed(5), 37 | z: data.acceleration.z.toFixed(5) 38 | }); 39 | }.bind(this)); 40 | }, 41 | componentWillUnmount: function () { 42 | Accelerometer.stopAccelerometerUpdates(); 43 | }, 44 | handleStart: function () { 45 | Accelerometer.startAccelerometerUpdates(); 46 | this.setState({ 47 | gyro: true 48 | }); 49 | }, 50 | handleStop: function () { 51 | Accelerometer.stopAccelerometerUpdates(); 52 | this.setState({ 53 | x: 0, 54 | y: 0, 55 | z: 0, 56 | gyro: false 57 | }); 58 | }, 59 | render: function() { 60 | console.log(this.state); 61 | return ( 62 | 67 | x: {this.state.x} 68 | y: {this.state.y} 69 | z: {this.state.z} 70 | { 71 | (this.state.gyro) ? 72 | : 73 | 74 | } 75 | 76 | ); 77 | } 78 | }); 79 | 80 | module.exports = AccelerometerManager; 81 | -------------------------------------------------------------------------------- /Example/MotionExample/components/GyroscopeManager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * GyroscopeManager 3 | * 4 | * Created by Patrick Williams in beautiful Seattle, WA. 5 | */ 6 | 'use strict'; 7 | 8 | var React = require('react-native'); 9 | var Button = require('react-native-button'); 10 | var { 11 | Text, 12 | View, 13 | DeviceEventEmitter 14 | } = React; 15 | 16 | var { 17 | Gyroscope 18 | } = require('NativeModules'); 19 | 20 | 21 | Gyroscope.setGyroUpdateInterval(0.1); 22 | 23 | var GyroscopeManager = React.createClass({ 24 | getInitialState: function () { 25 | return { 26 | x: 0, 27 | y: 0, 28 | z: 0, 29 | gyro: false 30 | } 31 | }, 32 | componentDidMount: function () { 33 | DeviceEventEmitter.addListener('GyroData', function (data) { 34 | this.setState({ 35 | x: data.rotationRate.x.toFixed(5), 36 | y: data.rotationRate.y.toFixed(5), 37 | z: data.rotationRate.z.toFixed(5) 38 | }); 39 | }.bind(this)); 40 | }, 41 | componentWillUnmount: function () { 42 | Gyroscope.stopGyroUpdates(); 43 | }, 44 | handleStart: function () { 45 | Gyroscope.startGyroUpdates(); 46 | this.setState({ 47 | gyro: true 48 | }); 49 | }, 50 | handleStop: function () { 51 | Gyroscope.stopGyroUpdates(); 52 | this.setState({ 53 | x: 0, 54 | y: 0, 55 | z: 0, 56 | gyro: false 57 | }); 58 | }, 59 | render: function() { 60 | console.log(this.state); 61 | return ( 62 | 67 | x: {this.state.x} 68 | y: {this.state.y} 69 | z: {this.state.z} 70 | { 71 | (this.state.gyro) ? 72 | : 73 | 74 | } 75 | 76 | ); 77 | } 78 | }); 79 | 80 | module.exports = GyroscopeManager; 81 | -------------------------------------------------------------------------------- /Example/MotionExample/components/Magnetometer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MagnetometerManager 3 | * 4 | * Created by Patrick Williams in beautiful Seattle, WA. 5 | */ 6 | 'use strict'; 7 | 8 | var React = require('react-native'); 9 | var Button = require('react-native-button'); 10 | var { 11 | Text, 12 | View, 13 | DeviceEventEmitter 14 | } = React; 15 | 16 | var { 17 | Magnetometer 18 | } = require('NativeModules'); 19 | 20 | 21 | Magnetometer.setMagnetometerUpdateInterval(0.1); 22 | 23 | var MagnetometerManager = React.createClass({ 24 | getInitialState: function () { 25 | return { 26 | x: 0, 27 | y: 0, 28 | z: 0, 29 | gyro: false 30 | } 31 | }, 32 | componentDidMount: function () { 33 | DeviceEventEmitter.addListener('MagnetometerData', function (data) { 34 | this.setState({ 35 | x: data.magneticField.x.toFixed(5), 36 | y: data.magneticField.y.toFixed(5), 37 | z: data.magneticField.z.toFixed(5) 38 | }); 39 | }.bind(this)); 40 | }, 41 | componentWillUnmount: function () { 42 | Magnetometer.stopMagnetometerUpdates(); 43 | }, 44 | handleStart: function () { 45 | Magnetometer.startMagnetometerUpdates(); 46 | this.setState({ 47 | gyro: true 48 | }); 49 | }, 50 | handleStop: function () { 51 | Magnetometer.stopMagnetometerUpdates(); 52 | this.setState({ 53 | x: 0, 54 | y: 0, 55 | z: 0, 56 | gyro: false 57 | }); 58 | }, 59 | render: function() { 60 | console.log(this.state); 61 | return ( 62 | 67 | x: {this.state.x} 68 | y: {this.state.y} 69 | z: {this.state.z} 70 | { 71 | (this.state.gyro) ? 72 | : 73 | 74 | } 75 | 76 | ); 77 | } 78 | }); 79 | 80 | module.exports = MagnetometerManager; 81 | -------------------------------------------------------------------------------- /Example/MotionExample/iOS/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Example/MotionExample/iOS/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import "RCTRootView.h" 13 | 14 | @implementation AppDelegate 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 17 | { 18 | NSURL *jsCodeLocation; 19 | 20 | // Loading JavaScript code - uncomment the one you want. 21 | 22 | // OPTION 1 23 | // Load from development server. Start the server from the repository root: 24 | // 25 | // $ npm start 26 | // 27 | // To run on device, change `localhost` to the IP address of your computer, and make sure your computer and 28 | // iOS device are on the same Wi-Fi network. 29 | jsCodeLocation = [NSURL URLWithString:@"http://10.0.1.4:8081/index.ios.bundle"]; 30 | 31 | // OPTION 2 32 | // Load from pre-bundled file on disk. To re-generate the static bundle, run 33 | // 34 | // $ curl 'http://localhost:8081/index.ios.bundle?dev=false&minify=true' -o iOS/main.jsbundle 35 | // 36 | // and uncomment the next following line 37 | // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 38 | 39 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 40 | moduleName:@"MotionManager" 41 | launchOptions:launchOptions]; 42 | 43 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 44 | UIViewController *rootViewController = [[UIViewController alloc] init]; 45 | rootViewController.view = rootView; 46 | self.window.rootViewController = rootViewController; 47 | [self.window makeKeyAndVisible]; 48 | return YES; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Example/MotionExample/iOS/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/MotionExample/iOS/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/MotionExample/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/MotionExample/iOS/main.jsbundle: -------------------------------------------------------------------------------- 1 | // Offline JS 2 | // To re-generate the offline bundle, run this from root of your project 3 | // $ curl 'http://localhost:8081/index.ios.bundle?dev=false&minify=true' -o iOS/main.jsbundle 4 | 5 | throw new Error('Offline JS file is empty. See iOS/main.jsbundle for instructions'); 6 | -------------------------------------------------------------------------------- /Example/MotionExample/iOS/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Example/MotionExample/index.ios.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MotionManger 3 | * 4 | * Created by Patrick Williams in beautiful Seattle, WA. 5 | */ 6 | 'use strict'; 7 | 8 | var React = require('react-native'); 9 | var { 10 | AppRegistry, 11 | Text, 12 | View, 13 | NavigatorIOS, 14 | TouchableHighlight, 15 | DeviceEventEmitter 16 | } = React; 17 | var Button = require('react-native-button'); 18 | 19 | var GyroscopeManager = require('./components/GyroscopeManager'); 20 | var AccelerometerManager = require('./components/AccelerometerManager'); 21 | var MagnetometerManager = require('./components/Magnetometer'); 22 | 23 | var routes = { 24 | gyroscope: { 25 | title: 'Gyroscope', 26 | component: GyroscopeManager 27 | }, 28 | accelerometer: { 29 | title: 'Accelerometer', 30 | component: AccelerometerManager 31 | }, 32 | magnetometer: { 33 | title: 'Magnetometer', 34 | component: MagnetometerManager 35 | } 36 | }; 37 | 38 | var MotionManager = React.createClass({ 39 | handleNavigationPress: function (route) { 40 | this.props.navigator.push(route); 41 | }, 42 | render: function () { 43 | return ( 44 | 48 | 49 | 50 | 51 | 52 | ); 53 | } 54 | }); 55 | 56 | routes.motion = { 57 | title: 'Motion', 58 | component: MotionManager 59 | }; 60 | 61 | var App = React.createClass({ 62 | render: function () { 63 | return ( 64 | 70 | ); 71 | } 72 | }); 73 | 74 | AppRegistry.registerComponent('MotionManager', function () { 75 | return App 76 | }); 77 | -------------------------------------------------------------------------------- /Example/MotionExample/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-motion-manager", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node_modules/react-native/packager/packager.sh" 7 | }, 8 | "dependencies": { 9 | "react-native": "^0.3.11", 10 | "react-native-button": "^1.0.0", 11 | "react-native-motion-manager": "^0.0.1" 12 | }, 13 | "description": "React Native wrapper for native iOS CMMotionManager", 14 | "main": "index.ios.js", 15 | "devDependencies": {}, 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/pwmckenna/react-native-motion-manager.git" 19 | }, 20 | "author": "Patrick Williams ", 21 | "license": "ISC", 22 | "bugs": { 23 | "url": "https://github.com/pwmckenna/react-native-motion-manager/issues" 24 | }, 25 | "homepage": "https://github.com/pwmckenna/react-native-motion-manager" 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notice 2 | 3 | I don't use this module anymore, and don't have time to maintain it. I've been handing out both github and npm write access to folks that seem interested, so feel free to ask. 4 | 5 | # react-native-motion-manager 6 | 7 | CMMotionManager wrapper for react-native, exposing Accelerometer, Gyroscope, and Magnetometer. 8 | 9 | ### Add it to your project 10 | 11 | 1. `npm install react-native-motion-manager@latest --save` 12 | 2. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` 13 | 3. Go to `node_modules` ➜ `react-native-motion-manager` and add `RNMotionManager.xcodeproj` 14 | 4. In XCode, in the project navigator, select your project. Add `libRNMotionManager.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` 15 | 5. Click `RNMotionManager.xcodeproj` in the project navigator and go the `Build Settings` tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for `Header Search Paths` and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` - mark both as `recursive`. 16 | 5. Run your project (`Cmd+R`) 17 | 18 | ### Setup trouble? 19 | 20 | If you get stuck, take a look at [Brent Vatne's blog](http://brentvatne.ca/packaging-react-native-component/). He was gracious enough to help out on this project, and his blog is my go to reference for this stuff. 21 | 22 | # Api 23 | 24 | ### Setup 25 | ```js 26 | var { 27 | Accelerometer, 28 | Gyroscope, 29 | Magnetometer 30 | } = require('NativeModules'); 31 | var { 32 | DeviceEventEmitter // will emit events that you can listen to 33 | } = React; 34 | ``` 35 | 36 | 37 | ### Accelerometer 38 | ```js 39 | Accelerometer.setAccelerometerUpdateInterval(0.1); // in seconds 40 | DeviceEventEmitter.addListener('AccelerationData', function (data) { 41 | /** 42 | * data.acceleration.x 43 | * data.acceleration.y 44 | * data.acceleration.z 45 | **/ 46 | }); 47 | Accelerometer.startAccelerometerUpdates(); // you'll start getting AccelerationData events above 48 | Accelerometer.stopAccelerometerUpdates(); 49 | ``` 50 | 51 | ### Gyroscope 52 | ```js 53 | Gyroscope.setGyroUpdateInterval(0.1); // in seconds 54 | DeviceEventEmitter.addListener('GyroData', function (data) { 55 | /** 56 | * data.rotationRate.x 57 | * data.rotationRate.y 58 | * data.rotationRate.z 59 | **/ 60 | }); 61 | Gyroscope.startGyroUpdates(); // you'll start getting GyroscopicData events above 62 | Gyroscope.stopGyroUpdates(); 63 | ``` 64 | 65 | ### Magnetometer 66 | ```js 67 | Magnetometer.setMagnetometerUpdateInterval(0.1); // in seconds 68 | DeviceEventEmitter.addListener('MagnetometerData', function (data) { 69 | /** 70 | * data.magneticField.x 71 | * data.magneticField.y 72 | * data.magneticField.z 73 | **/ 74 | }); 75 | Magnetometer.startMagnetometerUpdates(); // you'll start getting MagnetomerData events above 76 | Magnetometer.stopMagnetometerUpdates(); 77 | ``` 78 | 79 | # Example 80 | 81 | This repo contains an example react-native app to help get you started. [Source code here.](https://github.com/pwmckenna/react-native-motion-manager/tree/master/Example/MotionExample) 82 | 83 | ![](http://pwmckenna.com/react-native-motion-manager/motion.png) 84 | ![](http://pwmckenna.com/react-native-motion-manager/accelerometer.png) 85 | ![](http://pwmckenna.com/react-native-motion-manager/gyroscope.png) 86 | ![](http://pwmckenna.com/react-native-motion-manager/magnetometer.png) 87 | -------------------------------------------------------------------------------- /RNMotionManager.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BB9CC7F91AE0A2EB008A1D08 /* libRNMotionManager.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BB9CC7ED1AE0A2EB008A1D08 /* libRNMotionManager.a */; }; 11 | BB9CC8081AE0A5FE008A1D08 /* Gyroscope.m in Sources */ = {isa = PBXBuildFile; fileRef = BB9CC8071AE0A5FE008A1D08 /* Gyroscope.m */; }; 12 | BB9CC80E1AE0A707008A1D08 /* Accelerometer.m in Sources */ = {isa = PBXBuildFile; fileRef = BB9CC80B1AE0A707008A1D08 /* Accelerometer.m */; }; 13 | BB9CC80F1AE0A707008A1D08 /* Magnetometer.m in Sources */ = {isa = PBXBuildFile; fileRef = BB9CC80D1AE0A707008A1D08 /* Magnetometer.m */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXContainerItemProxy section */ 17 | BB9CC7FA1AE0A2EB008A1D08 /* PBXContainerItemProxy */ = { 18 | isa = PBXContainerItemProxy; 19 | containerPortal = BB9CC7E51AE0A2EB008A1D08 /* Project object */; 20 | proxyType = 1; 21 | remoteGlobalIDString = BB9CC7EC1AE0A2EB008A1D08; 22 | remoteInfo = RNMotionManager; 23 | }; 24 | /* End PBXContainerItemProxy section */ 25 | 26 | /* Begin PBXCopyFilesBuildPhase section */ 27 | BB9CC7EB1AE0A2EB008A1D08 /* CopyFiles */ = { 28 | isa = PBXCopyFilesBuildPhase; 29 | buildActionMask = 2147483647; 30 | dstPath = "include/$(PRODUCT_NAME)"; 31 | dstSubfolderSpec = 16; 32 | files = ( 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXCopyFilesBuildPhase section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | BB9CC7ED1AE0A2EB008A1D08 /* libRNMotionManager.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMotionManager.a; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | BB9CC7F81AE0A2EB008A1D08 /* RNMotionManagerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RNMotionManagerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | BB9CC7FE1AE0A2EB008A1D08 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | BB9CC8071AE0A5FE008A1D08 /* Gyroscope.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Gyroscope.m; sourceTree = ""; }; 43 | BB9CC8091AE0A614008A1D08 /* Gyroscope.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Gyroscope.h; sourceTree = ""; }; 44 | BB9CC80A1AE0A707008A1D08 /* Accelerometer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Accelerometer.h; sourceTree = ""; }; 45 | BB9CC80B1AE0A707008A1D08 /* Accelerometer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Accelerometer.m; sourceTree = ""; }; 46 | BB9CC80C1AE0A707008A1D08 /* Magnetometer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Magnetometer.h; sourceTree = ""; }; 47 | BB9CC80D1AE0A707008A1D08 /* Magnetometer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Magnetometer.m; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | BB9CC7EA1AE0A2EB008A1D08 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | BB9CC7F51AE0A2EB008A1D08 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | BB9CC7F91AE0A2EB008A1D08 /* libRNMotionManager.a in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | BB9CC7E41AE0A2EB008A1D08 = { 70 | isa = PBXGroup; 71 | children = ( 72 | BB9CC7EF1AE0A2EB008A1D08 /* RNMotionManager */, 73 | BB9CC7FC1AE0A2EB008A1D08 /* RNMotionManagerTests */, 74 | BB9CC7EE1AE0A2EB008A1D08 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | BB9CC7EE1AE0A2EB008A1D08 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | BB9CC7ED1AE0A2EB008A1D08 /* libRNMotionManager.a */, 82 | BB9CC7F81AE0A2EB008A1D08 /* RNMotionManagerTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | BB9CC7EF1AE0A2EB008A1D08 /* RNMotionManager */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | BB9CC8071AE0A5FE008A1D08 /* Gyroscope.m */, 91 | BB9CC8091AE0A614008A1D08 /* Gyroscope.h */, 92 | BB9CC80A1AE0A707008A1D08 /* Accelerometer.h */, 93 | BB9CC80B1AE0A707008A1D08 /* Accelerometer.m */, 94 | BB9CC80C1AE0A707008A1D08 /* Magnetometer.h */, 95 | BB9CC80D1AE0A707008A1D08 /* Magnetometer.m */, 96 | ); 97 | path = RNMotionManager; 98 | sourceTree = ""; 99 | }; 100 | BB9CC7FC1AE0A2EB008A1D08 /* RNMotionManagerTests */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | BB9CC7FD1AE0A2EB008A1D08 /* Supporting Files */, 104 | ); 105 | path = RNMotionManagerTests; 106 | sourceTree = ""; 107 | }; 108 | BB9CC7FD1AE0A2EB008A1D08 /* Supporting Files */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | BB9CC7FE1AE0A2EB008A1D08 /* Info.plist */, 112 | ); 113 | name = "Supporting Files"; 114 | sourceTree = ""; 115 | }; 116 | /* End PBXGroup section */ 117 | 118 | /* Begin PBXNativeTarget section */ 119 | BB9CC7EC1AE0A2EB008A1D08 /* RNMotionManager */ = { 120 | isa = PBXNativeTarget; 121 | buildConfigurationList = BB9CC8011AE0A2EB008A1D08 /* Build configuration list for PBXNativeTarget "RNMotionManager" */; 122 | buildPhases = ( 123 | BB9CC7E91AE0A2EB008A1D08 /* Sources */, 124 | BB9CC7EA1AE0A2EB008A1D08 /* Frameworks */, 125 | BB9CC7EB1AE0A2EB008A1D08 /* CopyFiles */, 126 | ); 127 | buildRules = ( 128 | ); 129 | dependencies = ( 130 | ); 131 | name = RNMotionManager; 132 | productName = RNMotionManager; 133 | productReference = BB9CC7ED1AE0A2EB008A1D08 /* libRNMotionManager.a */; 134 | productType = "com.apple.product-type.library.static"; 135 | }; 136 | BB9CC7F71AE0A2EB008A1D08 /* RNMotionManagerTests */ = { 137 | isa = PBXNativeTarget; 138 | buildConfigurationList = BB9CC8041AE0A2EB008A1D08 /* Build configuration list for PBXNativeTarget "RNMotionManagerTests" */; 139 | buildPhases = ( 140 | BB9CC7F41AE0A2EB008A1D08 /* Sources */, 141 | BB9CC7F51AE0A2EB008A1D08 /* Frameworks */, 142 | BB9CC7F61AE0A2EB008A1D08 /* Resources */, 143 | ); 144 | buildRules = ( 145 | ); 146 | dependencies = ( 147 | BB9CC7FB1AE0A2EB008A1D08 /* PBXTargetDependency */, 148 | ); 149 | name = RNMotionManagerTests; 150 | productName = RNMotionManagerTests; 151 | productReference = BB9CC7F81AE0A2EB008A1D08 /* RNMotionManagerTests.xctest */; 152 | productType = "com.apple.product-type.bundle.unit-test"; 153 | }; 154 | /* End PBXNativeTarget section */ 155 | 156 | /* Begin PBXProject section */ 157 | BB9CC7E51AE0A2EB008A1D08 /* Project object */ = { 158 | isa = PBXProject; 159 | attributes = { 160 | LastUpgradeCheck = 0610; 161 | ORGANIZATIONNAME = "Patrick Williams"; 162 | TargetAttributes = { 163 | BB9CC7EC1AE0A2EB008A1D08 = { 164 | CreatedOnToolsVersion = 6.1.1; 165 | }; 166 | BB9CC7F71AE0A2EB008A1D08 = { 167 | CreatedOnToolsVersion = 6.1.1; 168 | }; 169 | }; 170 | }; 171 | buildConfigurationList = BB9CC7E81AE0A2EB008A1D08 /* Build configuration list for PBXProject "RNMotionManager" */; 172 | compatibilityVersion = "Xcode 3.2"; 173 | developmentRegion = English; 174 | hasScannedForEncodings = 0; 175 | knownRegions = ( 176 | en, 177 | ); 178 | mainGroup = BB9CC7E41AE0A2EB008A1D08; 179 | productRefGroup = BB9CC7EE1AE0A2EB008A1D08 /* Products */; 180 | projectDirPath = ""; 181 | projectRoot = ""; 182 | targets = ( 183 | BB9CC7EC1AE0A2EB008A1D08 /* RNMotionManager */, 184 | BB9CC7F71AE0A2EB008A1D08 /* RNMotionManagerTests */, 185 | ); 186 | }; 187 | /* End PBXProject section */ 188 | 189 | /* Begin PBXResourcesBuildPhase section */ 190 | BB9CC7F61AE0A2EB008A1D08 /* Resources */ = { 191 | isa = PBXResourcesBuildPhase; 192 | buildActionMask = 2147483647; 193 | files = ( 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXResourcesBuildPhase section */ 198 | 199 | /* Begin PBXSourcesBuildPhase section */ 200 | BB9CC7E91AE0A2EB008A1D08 /* Sources */ = { 201 | isa = PBXSourcesBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | BB9CC80E1AE0A707008A1D08 /* Accelerometer.m in Sources */, 205 | BB9CC80F1AE0A707008A1D08 /* Magnetometer.m in Sources */, 206 | BB9CC8081AE0A5FE008A1D08 /* Gyroscope.m in Sources */, 207 | ); 208 | runOnlyForDeploymentPostprocessing = 0; 209 | }; 210 | BB9CC7F41AE0A2EB008A1D08 /* Sources */ = { 211 | isa = PBXSourcesBuildPhase; 212 | buildActionMask = 2147483647; 213 | files = ( 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | }; 217 | /* End PBXSourcesBuildPhase section */ 218 | 219 | /* Begin PBXTargetDependency section */ 220 | BB9CC7FB1AE0A2EB008A1D08 /* PBXTargetDependency */ = { 221 | isa = PBXTargetDependency; 222 | target = BB9CC7EC1AE0A2EB008A1D08 /* RNMotionManager */; 223 | targetProxy = BB9CC7FA1AE0A2EB008A1D08 /* PBXContainerItemProxy */; 224 | }; 225 | /* End PBXTargetDependency section */ 226 | 227 | /* Begin XCBuildConfiguration section */ 228 | BB9CC7FF1AE0A2EB008A1D08 /* Debug */ = { 229 | isa = XCBuildConfiguration; 230 | buildSettings = { 231 | ALWAYS_SEARCH_USER_PATHS = NO; 232 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 233 | CLANG_CXX_LIBRARY = "libc++"; 234 | CLANG_ENABLE_MODULES = YES; 235 | CLANG_ENABLE_OBJC_ARC = YES; 236 | CLANG_WARN_BOOL_CONVERSION = YES; 237 | CLANG_WARN_CONSTANT_CONVERSION = YES; 238 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 239 | CLANG_WARN_EMPTY_BODY = YES; 240 | CLANG_WARN_ENUM_CONVERSION = YES; 241 | CLANG_WARN_INT_CONVERSION = YES; 242 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 243 | CLANG_WARN_UNREACHABLE_CODE = YES; 244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 245 | COPY_PHASE_STRIP = NO; 246 | ENABLE_STRICT_OBJC_MSGSEND = YES; 247 | GCC_C_LANGUAGE_STANDARD = gnu99; 248 | GCC_DYNAMIC_NO_PIC = NO; 249 | GCC_OPTIMIZATION_LEVEL = 0; 250 | GCC_PREPROCESSOR_DEFINITIONS = ( 251 | "DEBUG=1", 252 | "$(inherited)", 253 | ); 254 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 255 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 256 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 257 | GCC_WARN_UNDECLARED_SELECTOR = YES; 258 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 259 | GCC_WARN_UNUSED_FUNCTION = YES; 260 | GCC_WARN_UNUSED_VARIABLE = YES; 261 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 262 | MTL_ENABLE_DEBUG_INFO = YES; 263 | ONLY_ACTIVE_ARCH = YES; 264 | SDKROOT = iphoneos; 265 | }; 266 | name = Debug; 267 | }; 268 | BB9CC8001AE0A2EB008A1D08 /* Release */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ALWAYS_SEARCH_USER_PATHS = NO; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 273 | CLANG_CXX_LIBRARY = "libc++"; 274 | CLANG_ENABLE_MODULES = YES; 275 | CLANG_ENABLE_OBJC_ARC = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INT_CONVERSION = YES; 282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | COPY_PHASE_STRIP = YES; 286 | ENABLE_NS_ASSERTIONS = NO; 287 | ENABLE_STRICT_OBJC_MSGSEND = YES; 288 | GCC_C_LANGUAGE_STANDARD = gnu99; 289 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 290 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 291 | GCC_WARN_UNDECLARED_SELECTOR = YES; 292 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 293 | GCC_WARN_UNUSED_FUNCTION = YES; 294 | GCC_WARN_UNUSED_VARIABLE = YES; 295 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 296 | MTL_ENABLE_DEBUG_INFO = NO; 297 | SDKROOT = iphoneos; 298 | VALIDATE_PRODUCT = YES; 299 | }; 300 | name = Release; 301 | }; 302 | BB9CC8021AE0A2EB008A1D08 /* Debug */ = { 303 | isa = XCBuildConfiguration; 304 | buildSettings = { 305 | HEADER_SEARCH_PATHS = ( 306 | "$(inherited)", 307 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 308 | "$(SRCROOT)/../react-native/React/**", 309 | "$(SRCROOT)/node_modules/react-native/React/**", 310 | ); 311 | OTHER_LDFLAGS = "-ObjC"; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | SKIP_INSTALL = YES; 314 | }; 315 | name = Debug; 316 | }; 317 | BB9CC8031AE0A2EB008A1D08 /* Release */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | HEADER_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 323 | "$(SRCROOT)/../react-native/React/**", 324 | "$(SRCROOT)/node_modules/react-native/React/**", 325 | ); 326 | OTHER_LDFLAGS = "-ObjC"; 327 | PRODUCT_NAME = "$(TARGET_NAME)"; 328 | SKIP_INSTALL = YES; 329 | }; 330 | name = Release; 331 | }; 332 | BB9CC8051AE0A2EB008A1D08 /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | FRAMEWORK_SEARCH_PATHS = ( 336 | "$(SDKROOT)/Developer/Library/Frameworks", 337 | "$(inherited)", 338 | ); 339 | GCC_PREPROCESSOR_DEFINITIONS = ( 340 | "DEBUG=1", 341 | "$(inherited)", 342 | ); 343 | INFOPLIST_FILE = RNMotionManagerTests/Info.plist; 344 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 345 | PRODUCT_NAME = "$(TARGET_NAME)"; 346 | }; 347 | name = Debug; 348 | }; 349 | BB9CC8061AE0A2EB008A1D08 /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | FRAMEWORK_SEARCH_PATHS = ( 353 | "$(SDKROOT)/Developer/Library/Frameworks", 354 | "$(inherited)", 355 | ); 356 | INFOPLIST_FILE = RNMotionManagerTests/Info.plist; 357 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | }; 360 | name = Release; 361 | }; 362 | /* End XCBuildConfiguration section */ 363 | 364 | /* Begin XCConfigurationList section */ 365 | BB9CC7E81AE0A2EB008A1D08 /* Build configuration list for PBXProject "RNMotionManager" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | BB9CC7FF1AE0A2EB008A1D08 /* Debug */, 369 | BB9CC8001AE0A2EB008A1D08 /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | BB9CC8011AE0A2EB008A1D08 /* Build configuration list for PBXNativeTarget "RNMotionManager" */ = { 375 | isa = XCConfigurationList; 376 | buildConfigurations = ( 377 | BB9CC8021AE0A2EB008A1D08 /* Debug */, 378 | BB9CC8031AE0A2EB008A1D08 /* Release */, 379 | ); 380 | defaultConfigurationIsVisible = 0; 381 | defaultConfigurationName = Release; 382 | }; 383 | BB9CC8041AE0A2EB008A1D08 /* Build configuration list for PBXNativeTarget "RNMotionManagerTests" */ = { 384 | isa = XCConfigurationList; 385 | buildConfigurations = ( 386 | BB9CC8051AE0A2EB008A1D08 /* Debug */, 387 | BB9CC8061AE0A2EB008A1D08 /* Release */, 388 | ); 389 | defaultConfigurationIsVisible = 0; 390 | defaultConfigurationName = Release; 391 | }; 392 | /* End XCConfigurationList section */ 393 | }; 394 | rootObject = BB9CC7E51AE0A2EB008A1D08 /* Project object */; 395 | } 396 | -------------------------------------------------------------------------------- /RNMotionManager/Accelerometer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Accelerometer.h 3 | // 4 | // Created by Patrick Williams in beautiful Seattle, WA. 5 | // 6 | 7 | #import 8 | #import 9 | 10 | @interface Accelerometer : NSObject { 11 | CMMotionManager *_motionManager; 12 | } 13 | - (void) setAccelerometerUpdateInterval:(double) interval; 14 | - (void) getAccelerometerUpdateInterval:(RCTResponseSenderBlock) cb; 15 | - (void) getAccelerometerData:(RCTResponseSenderBlock) cb; 16 | - (void) startAccelerometerUpdates; 17 | - (void) stopAccelerometerUpdates; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /RNMotionManager/Accelerometer.m: -------------------------------------------------------------------------------- 1 | // 2 | // Accelerometer.m 3 | // 4 | // Created by Patrick Williams in beautiful Seattle, WA. 5 | // 6 | 7 | #import 8 | #import 9 | #import "Accelerometer.h" 10 | 11 | @implementation Accelerometer 12 | 13 | @synthesize bridge = _bridge; 14 | 15 | RCT_EXPORT_MODULE(); 16 | 17 | - (id) init { 18 | self = [super init]; 19 | NSLog(@"Accelerometer"); 20 | 21 | if (self) { 22 | self->_motionManager = [[CMMotionManager alloc] init]; 23 | //Accelerometer 24 | if([self->_motionManager isAccelerometerAvailable]) 25 | { 26 | NSLog(@"Accelerometer available"); 27 | /* Start the accelerometer if it is not active already */ 28 | if([self->_motionManager isAccelerometerActive] == NO) 29 | { 30 | NSLog(@"Accelerometer active"); 31 | } else { 32 | NSLog(@"Accelerometer not active"); 33 | } 34 | } 35 | else 36 | { 37 | NSLog(@"Accelerometer not Available!"); 38 | } 39 | } 40 | return self; 41 | } 42 | 43 | RCT_EXPORT_METHOD(setAccelerometerUpdateInterval:(double) interval) { 44 | NSLog(@"setAccelerometerUpdateInterval: %f", interval); 45 | 46 | [self->_motionManager setAccelerometerUpdateInterval:interval]; 47 | } 48 | 49 | RCT_EXPORT_METHOD(getAccelerometerUpdateInterval:(RCTResponseSenderBlock) cb) { 50 | double interval = self->_motionManager.accelerometerUpdateInterval; 51 | NSLog(@"getAccelerometerUpdateInterval: %f", interval); 52 | cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); 53 | } 54 | 55 | RCT_EXPORT_METHOD(getAccelerometerData:(RCTResponseSenderBlock) cb) { 56 | double x = self->_motionManager.accelerometerData.acceleration.x; 57 | double y = self->_motionManager.accelerometerData.acceleration.y; 58 | double z = self->_motionManager.accelerometerData.acceleration.z; 59 | double timestamp = self->_motionManager.accelerometerData.timestamp; 60 | 61 | NSLog(@"getAccelerometerData: %f, %f, %f, %f", x, y, z, timestamp); 62 | 63 | cb(@[[NSNull null], @{ 64 | @"acceleration": @{ 65 | @"x" : [NSNumber numberWithDouble:x], 66 | @"y" : [NSNumber numberWithDouble:y], 67 | @"z" : [NSNumber numberWithDouble:z], 68 | @"timestamp" : [NSNumber numberWithDouble:timestamp] 69 | } 70 | }] 71 | ); 72 | } 73 | 74 | RCT_EXPORT_METHOD(startAccelerometerUpdates) { 75 | NSLog(@"startAccelerometerUpdates"); 76 | [self->_motionManager startAccelerometerUpdates]; 77 | 78 | /* Receive the ccelerometer data on this block */ 79 | [self->_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] 80 | withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) 81 | { 82 | double x = accelerometerData.acceleration.x; 83 | double y = accelerometerData.acceleration.y; 84 | double z = accelerometerData.acceleration.z; 85 | double timestamp = accelerometerData.timestamp; 86 | NSLog(@"startAccelerometerUpdates: %f, %f, %f, %f", x, y, z, timestamp); 87 | 88 | [self.bridge.eventDispatcher sendDeviceEventWithName:@"AccelerationData" body:@{ 89 | @"acceleration": @{ 90 | @"x" : [NSNumber numberWithDouble:x], 91 | @"y" : [NSNumber numberWithDouble:y], 92 | @"z" : [NSNumber numberWithDouble:z], 93 | @"timestamp" : [NSNumber numberWithDouble:timestamp] 94 | } 95 | }]; 96 | }]; 97 | 98 | } 99 | 100 | RCT_EXPORT_METHOD(stopAccelerometerUpdates) { 101 | NSLog(@"stopAccelerometerUpdates"); 102 | [self->_motionManager stopAccelerometerUpdates]; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /RNMotionManager/Gyroscope.h: -------------------------------------------------------------------------------- 1 | // 2 | // Gyroscope.h 3 | // 4 | // Created by Patrick Williams in beautiful Seattle, WA. 5 | // 6 | 7 | #import 8 | #import 9 | 10 | @interface Gyroscope : NSObject { 11 | CMMotionManager *_motionManager; 12 | } 13 | - (void) setGyroUpdateInterval:(double) interval; 14 | - (void) getGyroUpdateInterval:(RCTResponseSenderBlock) cb; 15 | - (void) getGyroData:(RCTResponseSenderBlock) cb; 16 | - (void) startGyroUpdates; 17 | - (void) stopGyroUpdates; 18 | 19 | @end -------------------------------------------------------------------------------- /RNMotionManager/Gyroscope.m: -------------------------------------------------------------------------------- 1 | // 2 | // Gyroscope.m 3 | // 4 | // Created by Patrick Williams in beautiful Seattle, WA. 5 | // 6 | 7 | #import 8 | #import 9 | #import "Gyroscope.h" 10 | 11 | @implementation Gyroscope 12 | 13 | @synthesize bridge = _bridge; 14 | 15 | RCT_EXPORT_MODULE(); 16 | 17 | - (id) init { 18 | self = [super init]; 19 | NSLog(@"Gyroscope"); 20 | 21 | if (self) { 22 | self->_motionManager = [[CMMotionManager alloc] init]; 23 | //Gyroscope 24 | if([self->_motionManager isGyroAvailable]) 25 | { 26 | NSLog(@"Gyroscope available"); 27 | /* Start the gyroscope if it is not active already */ 28 | if([self->_motionManager isGyroActive] == NO) 29 | { 30 | NSLog(@"Gyroscope active"); 31 | } else { 32 | NSLog(@"Gyroscope not active"); 33 | } 34 | } 35 | else 36 | { 37 | NSLog(@"Gyroscope not Available!"); 38 | } 39 | } 40 | return self; 41 | } 42 | 43 | RCT_EXPORT_METHOD(setGyroUpdateInterval:(double) interval) { 44 | NSLog(@"setGyroUpdateInterval: %f", interval); 45 | 46 | [self->_motionManager setGyroUpdateInterval:interval]; 47 | } 48 | 49 | RCT_EXPORT_METHOD(getGyroUpdateInterval:(RCTResponseSenderBlock) cb) { 50 | double interval = self->_motionManager.gyroUpdateInterval; 51 | NSLog(@"getGyroUpdateInterval: %f", interval); 52 | cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); 53 | } 54 | 55 | RCT_EXPORT_METHOD(getGyroData:(RCTResponseSenderBlock) cb) { 56 | double x = self->_motionManager.gyroData.rotationRate.x; 57 | double y = self->_motionManager.gyroData.rotationRate.y; 58 | double z = self->_motionManager.gyroData.rotationRate.z; 59 | double timestamp = self->_motionManager.gyroData.timestamp; 60 | 61 | NSLog(@"getGyroData: %f, %f, %f, %f", x, y, z, timestamp); 62 | 63 | cb(@[[NSNull null], @{ 64 | @"rotationRate": @{ 65 | @"x" : [NSNumber numberWithDouble:x], 66 | @"y" : [NSNumber numberWithDouble:y], 67 | @"z" : [NSNumber numberWithDouble:z], 68 | @"timestamp" : [NSNumber numberWithDouble:timestamp] 69 | } 70 | }] 71 | ); 72 | } 73 | 74 | RCT_EXPORT_METHOD(startGyroUpdates) { 75 | NSLog(@"startGyroUpdates"); 76 | [self->_motionManager startGyroUpdates]; 77 | 78 | /* Receive the gyroscope data on this block */ 79 | [self->_motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] 80 | withHandler:^(CMGyroData *gyroData, NSError *error) 81 | { 82 | double x = gyroData.rotationRate.x; 83 | double y = gyroData.rotationRate.y; 84 | double z = gyroData.rotationRate.z; 85 | double timestamp = gyroData.timestamp; 86 | NSLog(@"startGyroUpdates: %f, %f, %f, %f", x, y, z, timestamp); 87 | 88 | [self.bridge.eventDispatcher sendDeviceEventWithName:@"GyroData" body:@{ 89 | @"rotationRate": @{ 90 | @"x" : [NSNumber numberWithDouble:x], 91 | @"y" : [NSNumber numberWithDouble:y], 92 | @"z" : [NSNumber numberWithDouble:z], 93 | @"timestamp" : [NSNumber numberWithDouble:timestamp] 94 | } 95 | }]; 96 | }]; 97 | 98 | } 99 | 100 | RCT_EXPORT_METHOD(stopGyroUpdates) { 101 | NSLog(@"stopGyroUpdates"); 102 | [self->_motionManager stopGyroUpdates]; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /RNMotionManager/Magnetometer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Magnetometer.h 3 | // 4 | // Created by Patrick Williams in beautiful Seattle, WA. 5 | // 6 | 7 | #import 8 | #import 9 | 10 | @interface Magnetometer : NSObject { 11 | CMMotionManager *_motionManager; 12 | } 13 | - (void) setMagnetometerUpdateInterval:(double) interval; 14 | - (void) getMagnetometerUpdateInterval:(RCTResponseSenderBlock) cb; 15 | - (void) getMagnetometerData:(RCTResponseSenderBlock) cb; 16 | - (void) startMagnetometerUpdates; 17 | - (void) stopMagnetometerUpdates; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /RNMotionManager/Magnetometer.m: -------------------------------------------------------------------------------- 1 | // 2 | // Magnetometer.m 3 | // 4 | // Created by Patrick Williams in beautiful Seattle, WA. 5 | // 6 | 7 | #import 8 | #import 9 | #import "Magnetometer.h" 10 | 11 | @implementation Magnetometer 12 | 13 | @synthesize bridge = _bridge; 14 | 15 | RCT_EXPORT_MODULE(); 16 | 17 | - (id) init { 18 | self = [super init]; 19 | NSLog(@"Magnetometer"); 20 | 21 | if (self) { 22 | self->_motionManager = [[CMMotionManager alloc] init]; 23 | //Magnetometer 24 | if([self->_motionManager isMagnetometerAvailable]) 25 | { 26 | NSLog(@"Magnetometer available"); 27 | /* Start the Magnetometer if it is not active already */ 28 | if([self->_motionManager isMagnetometerActive] == NO) 29 | { 30 | NSLog(@"Magnetometer active"); 31 | } else { 32 | NSLog(@"Magnetometer not active"); 33 | } 34 | } 35 | else 36 | { 37 | NSLog(@"Magnetometer not Available!"); 38 | } 39 | } 40 | return self; 41 | } 42 | 43 | RCT_EXPORT_METHOD(setMagnetometerUpdateInterval:(double) interval) { 44 | NSLog(@"setMagnetometerUpdateInterval: %f", interval); 45 | 46 | [self->_motionManager setMagnetometerUpdateInterval:interval]; 47 | } 48 | 49 | RCT_EXPORT_METHOD(getMagnetometerUpdateInterval:(RCTResponseSenderBlock) cb) { 50 | double interval = self->_motionManager.magnetometerUpdateInterval; 51 | NSLog(@"getMagnetometerUpdateInterval: %f", interval); 52 | cb(@[[NSNull null], [NSNumber numberWithDouble:interval]]); 53 | } 54 | 55 | RCT_EXPORT_METHOD(getMagnetometerData:(RCTResponseSenderBlock) cb) { 56 | double x = self->_motionManager.magnetometerData.magneticField.x; 57 | double y = self->_motionManager.magnetometerData.magneticField.y; 58 | double z = self->_motionManager.magnetometerData.magneticField.z; 59 | double timestamp = self->_motionManager.magnetometerData.timestamp; 60 | 61 | NSLog(@"getMagnetometerData: %f, %f, %f, %f", x, y, z, timestamp); 62 | 63 | cb(@[[NSNull null], @{ 64 | @"magneticField": @{ 65 | @"x" : [NSNumber numberWithDouble:x], 66 | @"y" : [NSNumber numberWithDouble:y], 67 | @"z" : [NSNumber numberWithDouble:z], 68 | @"timestamp" : [NSNumber numberWithDouble:timestamp] 69 | } 70 | }] 71 | ); 72 | } 73 | 74 | RCT_EXPORT_METHOD(startMagnetometerUpdates) { 75 | NSLog(@"startMagnetometerUpdates"); 76 | [self->_motionManager startMagnetometerUpdates]; 77 | 78 | /* Receive the ccelerometer data on this block */ 79 | [self->_motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue mainQueue] 80 | withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) 81 | { 82 | double x = magnetometerData.magneticField.x; 83 | double y = magnetometerData.magneticField.y; 84 | double z = magnetometerData.magneticField.z; 85 | double timestamp = magnetometerData.timestamp; 86 | NSLog(@"startMagnetometerUpdates: %f, %f, %f, %f", x, y, z, timestamp); 87 | 88 | [self.bridge.eventDispatcher sendDeviceEventWithName:@"MagnetometerData" body:@{ 89 | @"magneticField": @{ 90 | @"x" : [NSNumber numberWithDouble:x], 91 | @"y" : [NSNumber numberWithDouble:y], 92 | @"z" : [NSNumber numberWithDouble:z], 93 | @"timestamp" : [NSNumber numberWithDouble:timestamp] 94 | } 95 | }]; 96 | }]; 97 | 98 | } 99 | 100 | RCT_EXPORT_METHOD(stopMagnetometerUpdates) { 101 | NSLog(@"stopMagnetometerUpdates"); 102 | [self->_motionManager stopMagnetometerUpdates]; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /RNMotionManagerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | pw.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var { Accelerometer, Gyroscope, Magnetometer } = require('react-native').NativeModules; 2 | 3 | module.exports = { Accelerometer, Gyroscope, Magnetometer }; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-motion-manager", 3 | "version": "0.0.6", 4 | "description": "A react-native interface for using the Gyroscope, Accelerometer and Magnetometer", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react-component", 11 | "react-native", 12 | "ios", 13 | "CMMotionManager", 14 | "MotionManager", 15 | "Gyroscope", 16 | "Accelerometer", 17 | "Magnetometer" 18 | ], 19 | "repository": { 20 | "type": "git", 21 | "url": "github.com:pwmckenna/react-native-motion-manager.git" 22 | }, 23 | "author": "Patrick Williams (http://pwmckenna.com/)", 24 | "contributors": [ 25 | "Brent Vatne " 26 | ], 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/pwmckenna/react-native-motion-manager/issues" 30 | }, 31 | "homepage": "https://github.com/pwmckenna/react-native-motion-manager", 32 | "peerDependencies": { 33 | "react-native": "*" 34 | } 35 | } 36 | --------------------------------------------------------------------------------