Repository: Pilloxa/react-native-nordic-dfu Branch: master Commit: d4bc769897e5 Files: 63 Total size: 111.7 KB Directory structure: gitextract_2s1lknuk/ ├── .gitattributes ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── android/ │ ├── build.gradle │ ├── gradle/ │ │ └── wrapper/ │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ └── java/ │ └── com/ │ └── pilloxa/ │ └── dfu/ │ ├── DfuService.java │ ├── NotificationActivity.java │ ├── RNNordicDfuModule.java │ └── RNNordicDfuPackage.java ├── circle.yml ├── example/ │ ├── .babelrc │ ├── .buckconfig │ ├── .flowconfig │ ├── .gitattributes │ ├── .gitignore │ ├── .watchmanconfig │ ├── __tests__/ │ │ ├── index.android.js │ │ └── index.ios.js │ ├── android/ │ │ ├── app/ │ │ │ ├── BUCK │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src/ │ │ │ └── main/ │ │ │ ├── AndroidManifest.xml │ │ │ ├── java/ │ │ │ │ └── com/ │ │ │ │ └── nordicdfuexample/ │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res/ │ │ │ └── values/ │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── build.gradle │ │ ├── gradle/ │ │ │ └── wrapper/ │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradle.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── keystores/ │ │ │ ├── BUCK │ │ │ └── debug.keystore.properties │ │ └── settings.gradle │ ├── app.js │ ├── app.json │ ├── index.android.js │ ├── index.ios.js │ ├── ios/ │ │ ├── NordicDFUExample/ │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj/ │ │ │ │ └── LaunchScreen.xib │ │ │ ├── Images.xcassets/ │ │ │ │ └── AppIcon.appiconset/ │ │ │ │ └── Contents.json │ │ │ ├── Info.plist │ │ │ └── main.m │ │ ├── NordicDFUExample.xcodeproj/ │ │ │ ├── project.pbxproj │ │ │ └── xcshareddata/ │ │ │ └── xcschemes/ │ │ │ └── NordicDFUExample.xcscheme │ │ ├── NordicDFUExample.xcworkspace/ │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata/ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ │ └── Podfile │ └── package.json ├── index.d.ts ├── index.js ├── ios/ │ ├── RNNordicDfu.h │ ├── RNNordicDfu.m │ └── RNNordicDfu.xcodeproj/ │ └── project.pbxproj ├── package.json └── react-native-nordic-dfu.podspec ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ *.pbxproj -text ================================================ FILE: .gitignore ================================================ # OSX # .DS_Store # node.js # node_modules/ npm-debug.log yarn-error.log # Xcode # build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa *.xcuserstate project.xcworkspace # Android/IntelliJ # build/ .idea .gradle local.properties *.iml # BUCK buck-out/ \.buckd/ *.keystore # CocoaPods Pods/ ================================================ FILE: .npmignore ================================================ # OSX # .DS_Store # node.js # node_modules/ npm-debug.log yarn-error.log # Xcode # build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa *.xcuserstate project.xcworkspace # Android/IntelliJ # build/ .idea .gradle local.properties *.iml # BUCK buck-out/ \.buckd/ *.keystore # Example dir example ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Pilloxa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # react-native-nordic-dfu [![npm version](https://badge.fury.io/js/react-native-nordic-dfu.svg)](https://badge.fury.io/js/react-native-nordic-dfu) [![CircleCI](https://circleci.com/gh/Pilloxa/react-native-nordic-dfu.svg?style=svg)](https://circleci.com/gh/Pilloxa/react-native-nordic-dfu) [![Known Vulnerabilities](https://snyk.io/test/github/pilloxa/react-native-nordic-dfu/badge.svg)](https://snyk.io/test/github/pilloxa/react-native-nordic-dfu) > ⚠️ Warning! This library is no longer actively maintained. For a more up to date version check out: [Salt-PepperEngineering/react-native-nordic-dfu](https://github.com/Salt-PepperEngineering/react-native-nordic-dfu) This library allows you to do a Device Firmware Update (DFU) of your nrf51 or nrf52 chip from Nordic Semiconductor. It works for both iOS and Android. For more info about the DFU process, see: [Resources](#resources) ## Installation Install and link the NPM package per usual with ```bash npm install --save react-native-nordic-dfu ``` or ```bash yarn add react-native-nordic-dfu ``` For React Native below 60.0 version ```bash react-native link react-native-nordic-dfu ``` ### Minimum requirements This project has been verified to work with the following dependencies, though other versions may work as well. | Dependency | Version | | ------------ | ------- | | React Native | 0.59.4 | | XCode | 10.2 | | Swift | 5.0 | | CocoaPods | 1.6.1 | | Gradle | 5.3.1 | ### iOS The iOS version of this library has native dependencies that need to be installed via `CocoaPods`, which is currently the only supported method for installing this library. (PR's for alternative installation methods are welcome!) Previous versions supported manual linking, but this was prone to errors every time a new version of XCode and/or Swift was released, which is why this support was dropped. If you've previously installed this library manually, you'll want to remove the old installation and replace it with CocoaPods. #### CocoaPods On your project directory; ```bash cd ios && pod install ``` If your React Native version below 0.60 or any problem occures on pod command, you can try these steps; Add the following to your `Podfile` ```ruby target "YourApp" do ... pod "react-native-nordic-dfu", path: "../node_modules/react-native-nordic-dfu" ... end ``` and in the same folder as the Podfile run ```bash pod install ``` Since there's native Swift dependencies you need to set which Swift version your project complies with. If you haven't already done this, open up your project with XCode and add a User-Defined setting under Build Settings: `SWIFT_VERSION = `. If your React Native version is higher than 0.60, probably it's already there. #### Bluetooth integration This library needs access to an instance of `CBCentralManager`, which you most likely will have instantiated already if you're using Bluetooth for other purposes than DFU in your project. To integrate with your existing Bluetooth setup, call `[RNNordicDfu setCentralManagerGetter:<...>]` with a block argument that returns your `CBCentralManager` instance. If you want control over the `CBCentralManager` instance after the DFU process is done you might need to provide the `onDFUComplete` and `onDFUError` callbacks to transfer back delegate control. Example code; ```swift ... ... #import "RNNordicDfu.h" #import "BleManager.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ ... ... [RNNordicDfu setCentralManagerGetter:^() { return [BleManager getCentralManager]; }]; // Reset manager delegate since the Nordic DFU lib "steals" control over it [RNNordicDfu setOnDFUComplete:^() { NSLog(@"onDFUComplete"); CBCentralManager * manager = [BleManager getCentralManager]; manager.delegate = [BleManager getInstance]; }]; [RNNordicDfu setOnDFUError:^() { NSLog(@"onDFUError"); CBCentralManager * manager = [BleManager getCentralManager]; manager.delegate = [BleManager getInstance]; }]; return YES; } ``` You can find them aslo in example project. On iOS side this library requires to BleManager module which that [react-native-ble-manager](https://github.com/innoveit/react-native-ble-manager) provides. It required because; - You need `BleManager.h` module on AppDelegate file for integration. - You should call `BleManager.start()` (for once) before the trigger a DFU process on iOS or you will get error like [this issue](https://github.com/Pilloxa/react-native-nordic-dfu/issues/82). ### Android Android requires that you have `FOREGROUND_SERVICE` permissions. You will need the following in your AndroidManifest.xml ``` ``` ## API ### startDFU Starts the DFU process Observe: The peripheral must have been discovered by the native BLE side so that the bluetooth stack knows about it. This library will not do a scan but only the actual connect and then the transfer. See the example project to see how it can be done in React Native. **Parameters** - `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** - `obj.deviceAddress` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The `identifier`\* of the device that should be updated - `obj.deviceName` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the device in the update notification (optional, default `null`) - `obj.filePath` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The file system path to the zip-file used for updating - `obj.alternativeAdvertisingNameEnabled` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Send unique name to device before it is switched into bootloader mode (iOS only) - defaults to `true` \* `identifier` — MAC address (Android) / UUID (iOS) **Examples** ```javascript import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu"; NordicDFU.startDFU({ deviceAddress: "C3:53:C0:39:2F:99", deviceName: "Pilloxa Pillbox", filePath: "/data/user/0/com.nordicdfuexample/files/RNFetchBlobTmp4of.zip", }) .then((res) => console.log("Transfer done:", res)) .catch(console.log); ``` Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A promise that resolves or rejects with the `deviceAddress` in the return value ### DFUEmitter Event emitter for DFU state and progress events **Examples** ```javascript import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu"; DFUEmitter.addListener( "DFUProgress", ({ percent, currentPart, partsTotal, avgSpeed, speed }) => { console.log("DFU progress: " + percent + "%"); } ); DFUEmitter.addListener("DFUStateChanged", ({ state }) => { console.log("DFU State:", state); }); ``` ## Selecting firmware file from local storage If your user will select the firmware file from local storage you should keep on mind some issues; You can use [react-native-document-picker](https://github.com/Elyx0/react-native-document-picker) library for file selecting process. ### On iOS You should select file type as `public.archive` or you will get null type error as like [this issue](https://github.com/Pilloxa/react-native-nordic-dfu/issues/100) ```js DocumentPicker.pick({ type: "public.archive" }); ``` If your device getting disconnect after enable DFU, you should set `false` value to `alternativeAdvertisingNameEnabled` prop while starting DFU. ```js NordicDFU.startDFU({ deviceAddress: "XXXXXXXX-XXXX-XXXX-XXXX-XX", filePath: firmwareFile.uri, alternativeAdvertisingNameEnabled: false, }); ``` ### On Android Some Android versions directly selecting file may can cause errors. If you get any file error you should copy it to your local storage. Like cache directory. You can use [react-native-fs](https://github.com/itinance/react-native-fs) for copying file. ```js const firmwareFile = await DocumentPicker.pick({ type: DocumentPicker.types.zip }) const destination = RNFS.CachesDirectoryPath + "/firmwareFile.zip"); await RNFS.copyFile(formatFile.uri, destination); NordicDFU.startDFU({ deviceAddress: "XX:XX:XX:XX:XX:XX", filePath: destination }) ``` If you getting disconnect error sometimes while starting DFU process, you should connect the device before start it. ## Example project Navigate to `example/` and run ```bash npm install ``` Run the iOS project with ```bash react-native run-ios ``` and the Android project with ```bash react-native run-android ``` ## Development PR's are always welcome! ## Resources - [DFU Introduction](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/examples_ble_dfu.html?cp=6_0_0_4_3_1 "BLE Bootloader/DFU") - [Secure DFU Introduction](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.0.0/ble_sdk_app_dfu_bootloader.html?cp=4_0_0_4_3_1 "BLE Secure DFU Bootloader") - [How to create init packet](https://github.com/NordicSemiconductor/Android-nRF-Connect/tree/master/init%20packet%20handling "Init packet handling") - [nRF51 Development Kit (DK)](http://www.nordicsemi.com/eng/Products/nRF51-DK "nRF51 DK") (compatible with Arduino Uno Revision 3) - [nRF52 Development Kit (DK)](http://www.nordicsemi.com/eng/Products/Bluetooth-Smart-Bluetooth-low-energy/nRF52-DK "nRF52 DK") (compatible with Arduino Uno Revision 3) ## Sponsored by [![pilloxa](https://pilloxa.com/images/pilloxa-round-logo.svg)](https://pilloxa.com) ================================================ FILE: android/build.gradle ================================================ buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.1.4' } } apply plugin: 'com.android.library' def DEFAULT_COMPILE_SDK_VERSION = 28 def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' def DEFAULT_TARGET_SDK_VERSION = 26 android { compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION defaultConfig { minSdkVersion 18 targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION versionCode 1 versionName "1.0" } lintOptions { abortOnError false } } repositories { mavenCentral() google() } dependencies { implementation 'com.facebook.react:react-native:+' implementation 'no.nordicsemi.android:dfu:1.8.0' } ================================================ FILE: android/gradle/wrapper/gradle-wrapper.properties ================================================ #Wed Nov 28 15:32:55 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip ================================================ FILE: android/src/main/AndroidManifest.xml ================================================ ================================================ FILE: android/src/main/java/com/pilloxa/dfu/DfuService.java ================================================ package com.pilloxa.dfu; import no.nordicsemi.android.dfu.DfuBaseService; import android.app.Activity; public class DfuService extends DfuBaseService { @Override protected Class getNotificationTarget() { /* * As a target activity the NotificationActivity is returned, not the MainActivity. This is because * the notification must create a new task: * * intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); * * when you press it. You can use NotificationActivity to check whether the new activity * is a root activity (that means no other activity was open earlier) or that some * other activity is already open. In the latter case the NotificationActivity will just be * closed. The system will restore the previous activity. However, if the application has been * closed during upload and you click the notification, a NotificationActivity will * be launched as a root activity. It will create and start the main activity and * terminate itself. * * This method may be used to restore the target activity in case the application * was closed or is open. It may also be used to recreate an activity history using * startActivities(...). */ return NotificationActivity.class; } @Override protected boolean isDebug() { // Here return true if you want the service to print more logs in LogCat. // Library's BuildConfig in current version of Android Studio is always set to DEBUG=false, so // make sure you return true or your.app.BuildConfig.DEBUG here. return true; } } ================================================ FILE: android/src/main/java/com/pilloxa/dfu/NotificationActivity.java ================================================ package com.pilloxa.dfu; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import androidx.annotation.Nullable; import com.facebook.react.ReactApplication; import com.facebook.react.ReactInstanceManager; import com.facebook.react.bridge.ReactContext; /** * Created by viktor on 2017-06-26. */ public class NotificationActivity extends Activity { private ReactInstanceManager reactInstanceManager; private ReactContext getReactContext() { reactInstanceManager = ((ReactApplication) getApplication()) .getReactNativeHost() .getReactInstanceManager(); return reactInstanceManager.getCurrentReactContext(); } public Class getMainActivityClass(ReactContext reactContext) { String packageName = reactContext.getPackageName(); Intent launchIntent = reactContext.getPackageManager().getLaunchIntentForPackage(packageName); String className = launchIntent.getComponent().getClassName(); try { return Class.forName(className); } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // If this activity is the root activity of the task, the app is not running if (isTaskRoot()) { ReactContext reactContext = getReactContext(); Class HostActivity = getMainActivityClass(reactContext); // Start the app before finishing final Intent intent = new Intent(this, HostActivity); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtras(getIntent().getExtras()); // copy all extras startActivity(intent); } // Now finish, which will drop you to the activity at which you were at the top of the task stack finish(); } } ================================================ FILE: android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java ================================================ package com.pilloxa.dfu; import android.app.NotificationManager; import android.content.Context; import android.os.Build; import android.os.Handler; import androidx.annotation.Nullable; import android.util.Log; import com.facebook.react.bridge.*; import com.facebook.react.modules.core.RCTNativeAppEventEmitter; import no.nordicsemi.android.dfu.*; public class RNNordicDfuModule extends ReactContextBaseJavaModule implements LifecycleEventListener { private final String dfuStateEvent = "DFUStateChanged"; private final String progressEvent = "DFUProgress"; private static final String name = "RNNordicDfu"; public static final String LOG_TAG = name; private final ReactApplicationContext reactContext; private Promise mPromise = null; public RNNordicDfuModule(ReactApplicationContext reactContext) { super(reactContext); reactContext.addLifecycleEventListener(this); this.reactContext = reactContext; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { DfuServiceInitiator.createDfuNotificationChannel(reactContext); } } @ReactMethod public void startDFU(String address, String name, String filePath, Promise promise) { mPromise = promise; final DfuServiceInitiator starter = new DfuServiceInitiator(address) .setKeepBond(false); if (name != null) { starter.setDeviceName(name); } starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true); starter.setZip(filePath); final DfuServiceController controller = starter.start(this.reactContext, DfuService.class); } @Override public String getName() { return name; } private void sendEvent(String eventName, @Nullable WritableMap params) { getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); } private void sendStateUpdate(String state, String deviceAddress) { WritableMap map = new WritableNativeMap(); Log.d(LOG_TAG, "State: " + state); map.putString("state", state); map.putString("deviceAddress", deviceAddress); sendEvent(dfuStateEvent, map); } @Override public void onHostResume() { DfuServiceListenerHelper.registerProgressListener(this.reactContext, mDfuProgressListener); } @Override public void onHostPause() { } @Override public void onHostDestroy() { DfuServiceListenerHelper.unregisterProgressListener(this.reactContext, mDfuProgressListener); } /** * The progress listener receives events from the DFU Service. * If is registered in onCreate() and unregistered in onDestroy() so methods here may also be called * when the screen is locked or the app went to the background. This is because the UI needs to have the * correct information after user comes back to the activity and this information can't be read from the service * as it might have been killed already (DFU completed or finished with error). */ private final DfuProgressListener mDfuProgressListener = new DfuProgressListenerAdapter() { @Override public void onDeviceConnecting(final String deviceAddress) { sendStateUpdate("CONNECTING", deviceAddress); } @Override public void onDfuProcessStarting(final String deviceAddress) { sendStateUpdate("DFU_PROCESS_STARTING", deviceAddress); } @Override public void onEnablingDfuMode(final String deviceAddress) { sendStateUpdate("ENABLING_DFU_MODE", deviceAddress); } @Override public void onFirmwareValidating(final String deviceAddress) { sendStateUpdate("FIRMWARE_VALIDATING", deviceAddress); } @Override public void onDeviceDisconnecting(final String deviceAddress) { sendStateUpdate("DEVICE_DISCONNECTING", deviceAddress); } @Override public void onDfuCompleted(final String deviceAddress) { if (mPromise != null) { WritableMap map = new WritableNativeMap(); map.putString("deviceAddress", deviceAddress); mPromise.resolve(map); mPromise = null; } sendStateUpdate("DFU_COMPLETED", deviceAddress); new Handler().postDelayed(new Runnable() { @Override public void run() { // if this activity is still open and upload process was completed, cancel the notification final NotificationManager manager = (NotificationManager) reactContext.getSystemService(Context.NOTIFICATION_SERVICE); manager.cancel(DfuService.NOTIFICATION_ID); } }, 200); } @Override public void onDfuAborted(final String deviceAddress) { sendStateUpdate("DFU_ABORTED", deviceAddress); if (mPromise != null) { mPromise.reject("2", "DFU ABORTED"); mPromise = null; } } @Override public void onProgressChanged(final String deviceAddress, final int percent, final float speed, final float avgSpeed, final int currentPart, final int partsTotal) { WritableMap map = new WritableNativeMap(); map.putString("deviceAddress", deviceAddress); map.putInt("percent", percent); map.putDouble("speed", speed); map.putDouble("avgSpeed", avgSpeed); map.putInt("currentPart", currentPart); map.putInt("partsTotal", partsTotal); sendEvent(progressEvent, map); } @Override public void onError(final String deviceAddress, final int error, final int errorType, final String message) { sendStateUpdate("DFU_FAILED", deviceAddress); if (mPromise != null) { mPromise.reject(Integer.toString(error), message); mPromise = null; } } }; } ================================================ FILE: android/src/main/java/com/pilloxa/dfu/RNNordicDfuPackage.java ================================================ package com.pilloxa.dfu; import java.util.Arrays; import java.util.Collections; import java.util.List; import com.facebook.react.ReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.bridge.JavaScriptModule; public class RNNordicDfuPackage implements ReactPackage { @Override public List createNativeModules(ReactApplicationContext reactContext) { return Arrays.asList(new RNNordicDfuModule(reactContext)); } public List> createJSModules() { return Collections.emptyList(); } @Override public List createViewManagers(ReactApplicationContext reactContext) { return Collections.emptyList(); } } ================================================ FILE: circle.yml ================================================ machine: node: version: 7 environment: PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/example/node_modules/.bin" JAVA_OPTS: "-Xms518m -Xmx2048m" GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"' dependencies: pre: - echo y | android update sdk --no-ui --all --filter "android-23" - echo y | android update sdk --no-ui --all --filter "build-tools-23.0.1" override: - cd example && yarn - cd example/android && ./gradlew --stacktrace app:dependencies cache_directories: - ~/.android - ~/.gradle test: override: # start the emulator - emulator -avd circleci-android22 -no-window: background: true parallel: true # wait for it to have booted - circle-android wait-for-boot - adb shell pm grant com.backtest android.permission.SYSTEM_ALERT_WINDOW # make sure that the project can be built - cd example/android && ./gradlew installDebug ================================================ FILE: example/.babelrc ================================================ { "presets": ["module:metro-react-native-babel-preset"] } ================================================ FILE: example/.buckconfig ================================================ [android] target = Google Inc.:Google APIs:23 [maven_repositories] central = https://repo1.maven.org/maven2 ================================================ FILE: example/.flowconfig ================================================ [ignore] ; We fork some components by platform .*/*[.]android.js ; Ignore "BUCK" generated dirs /\.buckd/ ; Ignore unexpected extra "@providesModule" .*/node_modules/.*/node_modules/fbjs/.* ; Ignore duplicate module providers ; For RN Apps installed via npm, "Libraries" folder is inside ; "node_modules/react-native" but in the source repo it is in the root .*/Libraries/react-native/React.js .*/Libraries/react-native/ReactNative.js [include] [libs] node_modules/react-native/Libraries/react-native/react-native-interface.js node_modules/react-native/flow flow/ [options] emoji=true module.system=haste experimental.strict_type_args=true munge_underscores=true module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' suppress_type=$FlowIssue suppress_type=$FlowFixMe suppress_type=$FixMe suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError unsafe.enable_getters_and_setters=true [version] ^0.45.0 ================================================ FILE: example/.gitattributes ================================================ *.pbxproj -text ================================================ FILE: example/.gitignore ================================================ # OSX # .DS_Store # Xcode # build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout *.moved-aside DerivedData *.hmap *.ipa *.xcuserstate project.xcworkspace # Android/IntelliJ # build/ .idea .gradle local.properties *.iml # node.js # node_modules/ npm-debug.log yarn-error.log # BUCK buck-out/ \.buckd/ *.keystore # fastlane # # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the # screenshots whenever they are needed. # For more information about the recommended setup visit: # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md fastlane/report.xml fastlane/Preview.html fastlane/screenshots jsconfig.json ================================================ FILE: example/.watchmanconfig ================================================ {} ================================================ FILE: example/__tests__/index.android.js ================================================ import 'react-native'; import React from 'react'; import Index from '../index.android.js'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; it('renders correctly', () => { const tree = renderer.create( ); }); ================================================ FILE: example/__tests__/index.ios.js ================================================ import 'react-native'; import React from 'react'; import Index from '../index.ios.js'; // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer'; it('renders correctly', () => { const tree = renderer.create( ); }); ================================================ FILE: example/android/app/BUCK ================================================ # To learn about Buck see [Docs](https://buckbuild.com/). # To run your application with Buck: # - install Buck # - `npm start` - to start the packager # - `cd android` # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck # - `buck install -r android/app` - compile, install and run application # lib_deps = [] for jarfile in glob(['libs/*.jar']): name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')] lib_deps.append(':' + name) prebuilt_jar( name = name, binary_jar = jarfile, ) for aarfile in glob(['libs/*.aar']): name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] lib_deps.append(':' + name) android_prebuilt_aar( name = name, aar = aarfile, ) android_library( name = "all-libs", exported_deps = lib_deps, ) android_library( name = "app-code", srcs = glob([ "src/main/java/**/*.java", ]), deps = [ ":all-libs", ":build_config", ":res", ], ) android_build_config( name = "build_config", package = "com.nordicdfuexample", ) android_resource( name = "res", package = "com.nordicdfuexample", res = "src/main/res", ) android_binary( name = "app", keystore = "//android/keystores:debug", manifest = "src/main/AndroidManifest.xml", package_type = "debug", deps = [ ":app-code", ], ) ================================================ FILE: example/android/app/build.gradle ================================================ apply plugin: "com.android.application" import com.android.build.OutputFile /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation * entryFile: "index.android.js", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ] */ apply from: "../../node_modules/react-native/react.gradle" /** * Set this to true to create two separate APKs instead of one: * - An APK that only works on ARM devices * - An APK that only works on x86 devices * The advantage is the size of the APK is reduced by about 4MB. * Upload all the APKs to the Play Store and people will download * the correct one based on the CPU architecture of their device. */ def enableSeparateBuildPerCPUArchitecture = false /** * Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = false android { compileSdkVersion 23 buildToolsVersion '23.0.1' defaultConfig { applicationId "com.nordicdfuexample" minSdkVersion 18 targetSdkVersion 22 versionCode 1 versionName "1.0" ndk { abiFilters "armeabi-v7a", "x86" } } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86" } } buildTypes { release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = ["armeabi-v7a":1, "x86":2] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { compile project(':react-native-fetch-blob') compile project(':react-native-nordic-dfu') compile project(':react-native-ble-manager') compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:+" // From node_modules } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } ================================================ FILE: example/android/app/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Disabling obfuscation is useful if you collect stack traces from production crashes # (unless you are using a system that supports de-obfuscate the stack traces). -dontobfuscate # React Native # Keep our interfaces so they can be used by other ProGuard rules. # See http://sourceforge.net/p/proguard/bugs/466/ -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip # Do not strip any method/class that is annotated with @DoNotStrip -keep @com.facebook.proguard.annotations.DoNotStrip class * -keep @com.facebook.common.internal.DoNotStrip class * -keepclassmembers class * { @com.facebook.proguard.annotations.DoNotStrip *; @com.facebook.common.internal.DoNotStrip *; } -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { void set*(***); *** get*(); } -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } -keep class * extends com.facebook.react.bridge.NativeModule { *; } -keepclassmembers,includedescriptorclasses class * { native ; } -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } -dontwarn com.facebook.react.** # TextLayoutBuilder uses a non-public Android constructor within StaticLayout. # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. -dontwarn android.text.StaticLayout # okhttp -keepattributes Signature -keepattributes *Annotation* -keep class okhttp3.** { *; } -keep interface okhttp3.** { *; } -dontwarn okhttp3.** # okio -keep class sun.misc.Unsafe { *; } -dontwarn java.nio.file.* -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -dontwarn okio.** ================================================ FILE: example/android/app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: example/android/app/src/main/java/com/nordicdfuexample/MainActivity.java ================================================ package com.nordicdfuexample; import com.facebook.react.ReactActivity; public class MainActivity extends ReactActivity { /** * Returns the name of the main component registered from JavaScript. * This is used to schedule rendering of the component. */ @Override protected String getMainComponentName() { return "NordicDFUExample"; } } ================================================ FILE: example/android/app/src/main/java/com/nordicdfuexample/MainApplication.java ================================================ package com.nordicdfuexample; import android.app.Application; import com.facebook.react.ReactApplication; import com.RNFetchBlob.RNFetchBlobPackage; import com.pilloxa.dfu.RNNordicDfuPackage; import it.innove.BleManagerPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; import java.util.Arrays; import java.util.List; public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RNFetchBlobPackage(), new RNNordicDfuPackage(), new BleManagerPackage() ); } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); } } ================================================ FILE: example/android/app/src/main/res/values/strings.xml ================================================ NordicDFUExample ================================================ FILE: example/android/app/src/main/res/values/styles.xml ================================================ ================================================ FILE: example/android/build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } } } ================================================ FILE: example/android/gradle/wrapper/gradle-wrapper.properties ================================================ #Mon Jun 26 16:03:16 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip ================================================ FILE: example/android/gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true android.useDeprecatedNdk=true ================================================ FILE: example/android/gradlew ================================================ #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # For Cygwin, ensure paths are in UNIX format before anything is touched. if $cygwin ; then [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` fi # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" cd "$SAVED" >&- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ================================================ FILE: example/android/gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: example/android/keystores/BUCK ================================================ keystore( name = "debug", properties = "debug.keystore.properties", store = "debug.keystore", visibility = [ "PUBLIC", ], ) ================================================ FILE: example/android/keystores/debug.keystore.properties ================================================ key.store=debug.keystore key.alias=androiddebugkey key.store.password=android key.alias.password=android ================================================ FILE: example/android/settings.gradle ================================================ rootProject.name = 'NordicDFUExample' include ':react-native-fetch-blob' project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android') include ':react-native-nordic-dfu' project(':react-native-nordic-dfu').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-nordic-dfu/android') include ':react-native-ble-manager' project(':react-native-ble-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ble-manager/android') include ':app' ================================================ FILE: example/app.js ================================================ /** * An example project that downloads a zip file, connects to a device and then flashes * it. */ import React, { Component } from "react"; import { AppRegistry, TouchableHighlight, NativeModules, NativeEventEmitter, Platform, StyleSheet, Text, View, Image } from "react-native"; import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu"; import RNFetchBlob from "rn-fetch-blob"; import BleManager from "react-native-ble-manager"; const BleManagerModule = NativeModules.BleManager; const bleManagerEmitter = new NativeEventEmitter(BleManagerModule); const DEVICE_ID = "C3:53:A0:31:2F:14"; const FB = RNFetchBlob.config({ fileCache: true, appendExt: "zip" }); export default class NordicDFUExample extends Component { constructor(props) { super(props); this.handleDeviceDiscovered = this.handleDeviceDiscovered.bind(this); this.startScan = this.startScan.bind(this); this.handleStopScan = this.handleStopScan.bind(this); this.state = { imagefile: false, scanning: false, deviceFound: false, dfuState: "Not started", progress: 0 }; } componentDidMount() { DFUEmitter.addListener("DFUProgress", ({ percent }) => { console.log("DFU progress:", percent); this.setState({ progress: percent }); }); DFUEmitter.addListener("DFUStateChanged", ({ state }) => { console.log("DFU state:", state); this.setState({ dfuState: state }); }); FB.fetch("GET", "http://localhost:1234/app.zip").then(res => { console.log("file saved to", res.path()); this.setState({ imagefile: res.path() }); }); BleManager.start({ showAlert: false, allowDuplicates: false }); bleManagerEmitter.addListener("BleManagerStopScan", this.handleStopScan); bleManagerEmitter.addListener( "BleManagerDiscoverPeripheral", this.handleDeviceDiscovered ); this.startScan(); } // #### DFU ####################################################### startDFU() { console.log("Starting DFU"); NordicDFU.startDFU({ deviceAddress: DEVICE_ID, name: "Pilloxa Board", filePath: this.state.imagefile }) .then(res => console.log("Transfer done: ", res)) .catch(console.log); } // #### BLUETOOTH ################################################# handleDeviceDiscovered({ id }) { if (id == DEVICE_ID) { this.setState({ deviceFound: true, scanning: false }); } } handleStopScan() { console.log("Scan is stopped"); if (this.state.scanning) { this.startScan(); } } startScan() { BleManager.scan([], 3, true).then(results => { console.log("Scanning..."); this.setState({ scanning: true }); }); } // #### RENDER ######################################################### render() { return ( {this.state.dfuState} {"DFU progress: " + this.state.progress + " %"} {this.state.scanning ? "Scanning for: " + DEVICE_ID : "Not scanning"} {this.state.deviceFound ? "Found device: " + DEVICE_ID : "Device not found"} {this.state.deviceFound ? Start DFU : null} ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF" }, welcome: { fontSize: 20, textAlign: "center", margin: 10 }, instructions: { textAlign: "center", color: "#333333", marginBottom: 5 } }); AppRegistry.registerComponent("NordicDFUExample", () => NordicDFUExample); ================================================ FILE: example/app.json ================================================ { "name": "NordicDFUExample", "displayName": "NordicDFUExample" } ================================================ FILE: example/index.android.js ================================================ /** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from "react"; import { AppRegistry } from "react-native"; import NordicDFUExample from "./app"; AppRegistry.registerComponent("NordicDFUExample", () => NordicDFUExample); ================================================ FILE: example/index.ios.js ================================================ /** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from "react"; import { AppRegistry } from "react-native"; import NordicDFUExample from "./app"; AppRegistry.registerComponent("NordicDFUExample", () => NordicDFUExample); ================================================ FILE: example/ios/NordicDFUExample/AppDelegate.h ================================================ /** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #import @interface AppDelegate : UIResponder @property (nonatomic, strong) UIWindow *window; @end ================================================ FILE: example/ios/NordicDFUExample/AppDelegate.m ================================================ /** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #import "AppDelegate.h" #import #import #import "RNNordicDfu.h" #import "BleManager.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"NordicDFUExample" initialProperties:nil launchOptions:launchOptions]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; [RNNordicDfu setCentralManagerGetter:^() { return [BleManager getCentralManager]; }]; // Reset manager delegate since the Nordic DFU lib "steals" control over it [RNNordicDfu setOnDFUComplete:^() { NSLog(@"onDFUComplete"); CBCentralManager * manager = [BleManager getCentralManager]; manager.delegate = [BleManager getInstance]; }]; [RNNordicDfu setOnDFUError:^() { NSLog(@"onDFUError"); CBCentralManager * manager = [BleManager getCentralManager]; manager.delegate = [BleManager getInstance]; }]; return YES; } @end ================================================ FILE: example/ios/NordicDFUExample/Base.lproj/LaunchScreen.xib ================================================ ================================================ FILE: example/ios/NordicDFUExample/Images.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "iphone", "size" : "20x20", "scale" : "2x" }, { "idiom" : "iphone", "size" : "20x20", "scale" : "3x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "3x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "3x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "3x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: example/ios/NordicDFUExample/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleDisplayName NordicDFUExample CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSRequiresIPhoneOS NSAppTransportSecurity NSExceptionDomains localhost NSExceptionAllowsInsecureHTTPLoads NSLocationWhenInUseUsageDescription UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance ================================================ FILE: example/ios/NordicDFUExample/main.m ================================================ /** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ #import #import "AppDelegate.h" int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } ================================================ FILE: example/ios/NordicDFUExample.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; AFBD98CE42EE4D292DE30278 /* Pods_NordicDFUExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6478854F2D98962939006428 /* Pods_NordicDFUExample.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ A53E61CC1F45E7370001EB4F /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; dstSubfolderSpec = 10; files = ( ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = ""; }; 13B07F961A680F5B00A75B9A /* NordicDFUExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NordicDFUExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = NordicDFUExample/AppDelegate.h; sourceTree = ""; }; 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = NordicDFUExample/AppDelegate.m; sourceTree = ""; }; 13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = NordicDFUExample/Images.xcassets; sourceTree = ""; }; 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = NordicDFUExample/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = NordicDFUExample/main.m; sourceTree = ""; }; 23DB7F518D38EFB05D9954C8 /* Pods-NordicDFUExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NordicDFUExample.release.xcconfig"; path = "Target Support Files/Pods-NordicDFUExample/Pods-NordicDFUExample.release.xcconfig"; sourceTree = ""; }; 6478854F2D98962939006428 /* Pods_NordicDFUExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NordicDFUExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; FA2EA6D15548AF2E9141F82E /* Pods-NordicDFUExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NordicDFUExample.debug.xcconfig"; path = "Target Support Files/Pods-NordicDFUExample/Pods-NordicDFUExample.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( AFBD98CE42EE4D292DE30278 /* Pods_NordicDFUExample.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 13B07FAE1A68108700A75B9A /* NordicDFUExample */ = { isa = PBXGroup; children = ( 008F07F21AC5B25A0029DE68 /* main.jsbundle */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 13B07FB01A68108700A75B9A /* AppDelegate.m */, 13B07FB51A68108700A75B9A /* Images.xcassets */, 13B07FB61A68108700A75B9A /* Info.plist */, 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, 13B07FB71A68108700A75B9A /* main.m */, ); name = NordicDFUExample; sourceTree = ""; }; 3A4D31ACCE1F1F6885CF77A1 /* Pods */ = { isa = PBXGroup; children = ( FA2EA6D15548AF2E9141F82E /* Pods-NordicDFUExample.debug.xcconfig */, 23DB7F518D38EFB05D9954C8 /* Pods-NordicDFUExample.release.xcconfig */, ); path = Pods; sourceTree = ""; }; 83CBB9F61A601CBA00E9B192 = { isa = PBXGroup; children = ( 13B07FAE1A68108700A75B9A /* NordicDFUExample */, 83CBBA001A601CBA00E9B192 /* Products */, 3A4D31ACCE1F1F6885CF77A1 /* Pods */, CD8C38820690DE8FB4BF3E99 /* Frameworks */, ); indentWidth = 2; sourceTree = ""; tabWidth = 2; }; 83CBBA001A601CBA00E9B192 /* Products */ = { isa = PBXGroup; children = ( 13B07F961A680F5B00A75B9A /* NordicDFUExample.app */, ); name = Products; sourceTree = ""; }; CD8C38820690DE8FB4BF3E99 /* Frameworks */ = { isa = PBXGroup; children = ( 6478854F2D98962939006428 /* Pods_NordicDFUExample.framework */, ); name = Frameworks; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 13B07F861A680F5B00A75B9A /* NordicDFUExample */ = { isa = PBXNativeTarget; buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "NordicDFUExample" */; buildPhases = ( 554227AE062BEDCA14FCD59E /* [CP] Check Pods Manifest.lock */, 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, A53E61CC1F45E7370001EB4F /* Embed Frameworks */, 4B0AD483234F0DC3E0F75BEF /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); dependencies = ( ); name = NordicDFUExample; productName = "Hello World"; productReference = 13B07F961A680F5B00A75B9A /* NordicDFUExample.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 83CBB9F71A601CBA00E9B192 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0830; ORGANIZATIONNAME = Facebook; TargetAttributes = { 13B07F861A680F5B00A75B9A = { DevelopmentTeam = X8M4Z7CAY5; }; }; }; buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "NordicDFUExample" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( English, en, Base, ); mainGroup = 83CBB9F61A601CBA00E9B192; productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 13B07F861A680F5B00A75B9A /* NordicDFUExample */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 13B07F8E1A680F5B00A75B9A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "Bundle React Native code and images"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; }; 4B0AD483234F0DC3E0F75BEF /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-NordicDFUExample/Pods-NordicDFUExample-frameworks.sh", "${BUILT_PRODUCTS_DIR}/DoubleConversion/DoubleConversion.framework", "${BUILT_PRODUCTS_DIR}/Folly/folly.framework", "${BUILT_PRODUCTS_DIR}/React/React.framework", "${BUILT_PRODUCTS_DIR}/ZIPFoundation/ZIPFoundation.framework", "${BUILT_PRODUCTS_DIR}/glog/glog.framework", "${BUILT_PRODUCTS_DIR}/iOSDFULibrary/iOSDFULibrary.framework", "${BUILT_PRODUCTS_DIR}/react-native-ble-manager/react_native_ble_manager.framework", "${BUILT_PRODUCTS_DIR}/react-native-nordic-dfu/react_native_nordic_dfu.framework", "${BUILT_PRODUCTS_DIR}/rn-fetch-blob/rn_fetch_blob.framework", "${BUILT_PRODUCTS_DIR}/yoga/yoga.framework", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( ); outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DoubleConversion.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/folly.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/React.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ZIPFoundation.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/glog.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/iOSDFULibrary.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/react_native_ble_manager.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/react_native_nordic_dfu.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/rn_fetch_blob.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/yoga.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-NordicDFUExample/Pods-NordicDFUExample-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; 554227AE062BEDCA14FCD59E /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( ); inputPaths = ( "${PODS_PODFILE_DIR_PATH}/Podfile.lock", "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( ); outputPaths = ( "$(DERIVED_FILE_DIR)/Pods-NordicDFUExample-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 13B07F871A680F5B00A75B9A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, 13B07FC11A68108700A75B9A /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ 13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = { isa = PBXVariantGroup; children = ( 13B07FB21A68108700A75B9A /* Base */, ); name = LaunchScreen.xib; path = NordicDFUExample; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = FA2EA6D15548AF2E9141F82E /* Pods-NordicDFUExample.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; DEAD_CODE_STRIPPING = NO; DEVELOPMENT_TEAM = X8M4Z7CAY5; ENABLE_BITCODE = NO; INFOPLIST_FILE = NordicDFUExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", "-lc++", ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = NordicDFUExample; VALID_ARCHS = "arm64 armv7 armv7s"; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; }; 13B07F951A680F5B00A75B9A /* Release */ = { isa = XCBuildConfiguration; baseConfigurationReference = 23DB7F518D38EFB05D9954C8 /* Pods-NordicDFUExample.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = X8M4Z7CAY5; ENABLE_BITCODE = NO; INFOPLIST_FILE = NordicDFUExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", "-lc++", ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = NordicDFUExample; VALID_ARCHS = "arm64 armv7 armv7s"; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; }; 83CBBA201A601CBA00E9B192 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_VERSION = 5; }; name = Debug; }; 83CBBA211A601CBA00E9B192 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_VERSION = 5; VALIDATE_PRODUCT = YES; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "NordicDFUExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 13B07F941A680F5B00A75B9A /* Debug */, 13B07F951A680F5B00A75B9A /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "NordicDFUExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 83CBBA201A601CBA00E9B192 /* Debug */, 83CBBA211A601CBA00E9B192 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; } ================================================ FILE: example/ios/NordicDFUExample.xcodeproj/xcshareddata/xcschemes/NordicDFUExample.xcscheme ================================================ ================================================ FILE: example/ios/NordicDFUExample.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: example/ios/NordicDFUExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist ================================================ IDEDidComputeMac32BitWarning ================================================ FILE: example/ios/NordicDFUExample.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings ================================================ ================================================ FILE: example/ios/Podfile ================================================ platform :ios, "9.0" # External dependencies contain Swift, important to add this line use_frameworks! target "NordicDFUExample" do # Standard React Native dependencies when using CocoaPods pod "yoga", path: "../node_modules/react-native/ReactCommon/yoga" pod "DoubleConversion", podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec" pod "glog", podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec" pod "Folly", podspec: "../node_modules/react-native/third-party-podspecs/Folly.podspec" pod "React", path: "../node_modules/react-native", subspecs: [ "Core", "CxxBridge", "DevSupport", "RCTBlob", "RCTImage", "RCTLinkingIOS", "RCTText", ] pod "react-native-ble-manager", path: "../node_modules/react-native-ble-manager" pod "rn-fetch-blob", path: "../node_modules/rn-fetch-blob" # replace this path with "../node_modules/react-native-nordic-dfu" or wherever # it's installed in your project pod "react-native-nordic-dfu", path: "../../" end ================================================ FILE: example/package.json ================================================ { "name": "NordicDFUExample", "version": "0.0.1", "private": true, "scripts": { "postinstall": "(cd ios && pod install)", "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.8.3", "react-native": "0.59.4", "react-native-ble-manager": "6.6.2", "react-native-nordic-dfu": "file:../", "rn-fetch-blob": "^0.10.12" } } ================================================ FILE: index.d.ts ================================================ declare module 'react-native-nordic-dfu' { export class NordicDFU { static startDFU({ deviceAddress, deviceName, filePath, alternativeAdvertisingNameEnabled }: { deviceAddress: string; deviceName?: string; filePath: string | null; alternativeAdvertisingNameEnabled?: boolean; }): Promise; } export interface IDfuUpdate { percent?: number; currentPart?: number; partsTotal?: number; avgSpeed?: number; speed?: number; state?: string; } export class DFUEmitter { static addListener( name: 'DFUProgress' | 'DFUStateChanged', handler: (update: IDfuUpdate) => void ): void; static removeAllListeners(name: 'DFUProgress' | 'DFUStateChanged'): void; } } ================================================ FILE: index.js ================================================ import { NativeModules, NativeEventEmitter, Platform } from "react-native"; const { RNNordicDfu } = NativeModules; const NordicDFU = { startDFU }; function rejectPromise(message) { return new Promise((resolve, reject) => { reject(new Error("NordicDFU.startDFU: " + message)); }); } /** * * Starts the DFU process * * Observe: The peripheral must have been discovered by the native BLE side so that the * bluetooth stack knows about it. This library will not do a scan but only * the actual connect and then the transfer. See the example project to see how it can be * done in React Native. * * For `alternativeAdvertisingNameEnabled` option below, see: * https://github.com/NordicSemiconductor/IOS-Pods-DFU-Library/blob/master/iOSDFULibrary/Classes/Implementation/DFUServiceInitiator.swift#L191 * * @param {Object} obj * @param {string} obj.deviceAddress The MAC address for the device that should be updated * @param {string} [obj.deviceName = null] The name of the device in the update notification * @param {string} obj.filePath The file system path to the zip-file used for updating * @param {Boolean} obj.alternativeAdvertisingNameEnabled Send unique name to device before it is switched into bootloader mode (iOS only) * @returns {Promise} A promise that resolves or rejects with the `deviceAddress` in the return value * * @example * import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu"; * * NordicDFU.startDFU({ * deviceAddress: "C3:53:C0:39:2F:99", * deviceName: "Pilloxa Pillbox", * filePath: "/data/user/0/com.nordicdfuexample/files/RNFetchBlobTmp4of.zip" * }) * .then(res => console.log("Transfer done:", res)) * .catch(console.log); */ function startDFU({ deviceAddress, deviceName = null, filePath, alternativeAdvertisingNameEnabled = true }) { if (deviceAddress == undefined) { return rejectPromise("No deviceAddress defined"); } if (filePath == undefined) { return rejectPromise("No filePath defined"); } const upperDeviceAddress = deviceAddress.toUpperCase(); if (Platform.OS === 'ios') { return RNNordicDfu.startDFU(upperDeviceAddress, deviceName, filePath, alternativeAdvertisingNameEnabled); } return RNNordicDfu.startDFU(upperDeviceAddress, deviceName, filePath); } /** * Event emitter for DFU state and progress events * * @const DFUEmitter * * @example * import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu"; * * DFUEmitter.addlistener("DFUProgress",({percent, currentPart, partsTotal, avgSpeed, speed}) => { * console.log("DFU progress: " + percent +"%"); * }); * * DFUEmitter.addListener("DFUStateChanged", ({state}) => { * console.log("DFU State:", state); * }) */ const DFUEmitter = new NativeEventEmitter(RNNordicDfu); export { NordicDFU, DFUEmitter }; ================================================ FILE: ios/RNNordicDfu.h ================================================ #import #import #import @import iOSDFULibrary; @interface RNNordicDfu : RCTEventEmitter @property (strong, nonatomic) NSString * deviceAddress; @property (strong, nonatomic) RCTPromiseResolveBlock resolve; @property (strong, nonatomic) RCTPromiseRejectBlock reject; + (void)setCentralManagerGetter:(CBCentralManager * (^)())getter; + (void)setOnDFUComplete:(void (^)())onComplete; + (void)setOnDFUError:(void (^)())onError; @end ================================================ FILE: ios/RNNordicDfu.m ================================================ #import "RNNordicDfu.h" #import @import iOSDFULibrary; static CBCentralManager * (^getCentralManager)(); static void (^onDFUComplete)(); static void (^onDFUError)(); @implementation RNNordicDfu RCT_EXPORT_MODULE(); NSString * const DFUProgressEvent = @"DFUProgress"; NSString * const DFUStateChangedEvent = @"DFUStateChanged"; - (NSArray *)supportedEvents { return @[DFUProgressEvent, DFUStateChangedEvent,]; } - (NSString *)stateDescription:(enum DFUState)state { switch (state) { case DFUStateAborted: return @"DFU_ABORTED"; case DFUStateStarting: return @"DFU_PROCESS_STARTING"; case DFUStateCompleted: return @"DFU_COMPLETED"; case DFUStateUploading: return @"DFU_STATE_UPLOADING"; case DFUStateConnecting: return @"CONNECTING"; case DFUStateValidating: return @"FIRMWARE_VALIDATING"; case DFUStateDisconnecting: return @"DEVICE_DISCONNECTING"; case DFUStateEnablingDfuMode: return @"ENABLING_DFU_MODE"; default: return @"UNKNOWN_STATE"; } } - (NSString *)errorDescription:(enum DFUError)error { switch(error) { case DFUErrorCrcError: return @"DFUErrorCrcError"; case DFUErrorBytesLost: return @"DFUErrorBytesLost"; case DFUErrorFileInvalid: return @"DFUErrorFileInvalid"; case DFUErrorFailedToConnect: return @"DFUErrorFailedToConnect"; case DFUErrorFileNotSpecified: return @"DFUErrorFileNotSpecified"; case DFUErrorBluetoothDisabled: return @"DFUErrorBluetoothDisabled"; case DFUErrorDeviceDisconnected: return @"DFUErrorDeviceDisconnected"; case DFUErrorDeviceNotSupported: return @"DFUErrorDeviceNotSupported"; case DFUErrorInitPacketRequired: return @"DFUErrorInitPacketRequired"; case DFUErrorUnsupportedResponse: return @"DFUErrorUnsupportedResponse"; case DFUErrorReadingVersionFailed: return @"DFUErrorReadingVersionFailed"; case DFUErrorRemoteLegacyDFUSuccess: return @"DFUErrorRemoteLegacyDFUSuccess"; case DFUErrorRemoteSecureDFUSuccess: return @"DFUErrorRemoteSecureDFUSuccess"; case DFUErrorServiceDiscoveryFailed: return @"DFUErrorServiceDiscoveryFailed"; case DFUErrorRemoteLegacyDFUCrcError: return @"DFUErrorRemoteLegacyDFUCrcError"; case DFUErrorEnablingControlPointFailed: return @"DFUErrorEnablingControlPointFailed"; case DFUErrorExtendedInitPacketRequired: return @"DFUErrorExtendedInitPacketRequired"; case DFUErrorReceivingNotificationFailed: return @"DFUErrorReceivingNotificationFailed"; case DFUErrorRemoteButtonlessDFUSuccess: return @"DFUErrorRemoteButtonlessDFUSuccess"; case DFUErrorRemoteLegacyDFUInvalidState: return @"DFUErrorRemoteLegacyDFUInvalidState"; case DFUErrorRemoteLegacyDFUNotSupported: return @"DFUErrorRemoteLegacyDFUNotSupported"; case DFUErrorWritingCharacteristicFailed: return @"DFUErrorWritingCharacteristicFailed"; case DFUErrorRemoteSecureDFUExtendedError: return @"DFUErrorRemoteSecureDFUExtendedError"; case DFUErrorRemoteSecureDFUInvalidObject: return @"DFUErrorRemoteSecureDFUInvalidObject"; case DFUErrorRemoteLegacyDFUOperationFailed: return @"DFUErrorRemoteLegacyDFUOperationFailed"; case DFUErrorRemoteSecureDFUOperationFailed: return @"DFUErrorRemoteSecureDFUOperationFailed"; case DFUErrorRemoteSecureDFUUnsupportedType: return @"DFUErrorRemoteSecureDFUUnsupportedType"; case DFUErrorRemoteLegacyDFUDataExceedsLimit: return @"DFUErrorRemoteLegacyDFUDataExceedsLimit"; case DFUErrorRemoteSecureDFUInvalidParameter: return @"DFUErrorRemoteSecureDFUInvalidParameter"; case DFUErrorRemoteSecureDFUSignatureMismatch: return @"DFUErrorRemoteSecureDFUSignatureMismatch"; case DFUErrorRemoteSecureDFUOpCodeNotSupported: return @"DFUErrorRemoteSecureDFUOpCodeNotSupported"; case DFUErrorRemoteButtonlessDFUOperationFailed: return @"DFUErrorRemoteButtonlessDFUOperationFailed"; case DFUErrorRemoteSecureDFUInsufficientResources: return @"DFUErrorRemoteSecureDFUInsufficientResources"; case DFUErrorRemoteSecureDFUOperationNotPermitted: return @"DFUErrorRemoteSecureDFUOperationNotPermitted"; case DFUErrorRemoteButtonlessDFUOpCodeNotSupported: return @"DFUErrorRemoteButtonlessDFUOpCodeNotSupported"; case DFUErrorRemoteExperimentalButtonlessDFUSuccess: return @"DFUErrorRemoteExperimentalButtonlessDFUSuccess"; case DFUErrorRemoteExperimentalButtonlessDFUOperationFailed: return @"DFUErrorRemoteExperimentalButtonlessDFUOperationFailed"; case DFUErrorRemoteExperimentalButtonlessDFUOpCodeNotSupported: return @"DFUErrorRemoteExperimentalButtonlessDFUOpCodeNotSupported"; default: return @"UNKNOWN_ERROR"; } } - (void)dfuStateDidChangeTo:(enum DFUState)state { NSDictionary * evtBody = @{@"deviceAddress": self.deviceAddress, @"state": [self stateDescription:state],}; [self sendEventWithName:DFUStateChangedEvent body:evtBody]; if (state == DFUStateCompleted) { if (onDFUComplete) { onDFUComplete(); } NSDictionary * resolveBody = @{@"deviceAddress": self.deviceAddress,}; self.resolve(resolveBody); } } - (void) dfuError:(enum DFUError)error didOccurWithMessage:(NSString * _Nonnull)message { if (onDFUError) { onDFUError(); } NSDictionary * evtBody = @{@"deviceAddress": self.deviceAddress, @"state": @"DFU_FAILED",}; [self sendEventWithName:DFUStateChangedEvent body:evtBody]; self.reject([self errorDescription:error], message, nil); } - (void)dfuProgressDidChangeFor:(NSInteger)part outOf:(NSInteger)totalParts to:(NSInteger)progress currentSpeedBytesPerSecond:(double)currentSpeedBytesPerSecond avgSpeedBytesPerSecond:(double)avgSpeedBytesPerSecond { NSDictionary * evtBody = @{@"deviceAddress": self.deviceAddress, @"currentPart": [NSNumber numberWithInteger:part], @"partsTotal": [NSNumber numberWithInteger:totalParts], @"percent": [NSNumber numberWithInteger:progress], @"speed": [NSNumber numberWithDouble:currentSpeedBytesPerSecond], @"avgSpeed": [NSNumber numberWithDouble:avgSpeedBytesPerSecond],}; [self sendEventWithName:DFUProgressEvent body:evtBody]; } - (void)logWith:(enum LogLevel)level message:(NSString * _Nonnull)message { NSLog(@"logWith: %ld message: '%@'", (long)level, message); } RCT_EXPORT_METHOD(startDFU:(NSString *)deviceAddress deviceName:(NSString *)deviceName filePath:(NSString *)filePath alternativeAdvertisingNameEnabled:(BOOL *)alternativeAdvertisingNameEnabled resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { self.deviceAddress = deviceAddress; self.resolve = resolve; self.reject = reject; if (!getCentralManager) { reject(@"nil_central_manager_getter", @"Attempted to start DFU without central manager getter", nil); } else { CBCentralManager * centralManager = getCentralManager(); if (!centralManager) { reject(@"nil_central_manager", @"Call to getCentralManager returned nil", nil); } else if (!deviceAddress) { reject(@"nil_device_address", @"Attempted to start DFU with nil deviceAddress", nil); } else if (!filePath) { reject(@"nil_file_path", @"Attempted to start DFU with nil filePath", nil); } else { NSUUID * uuid = [[NSUUID alloc] initWithUUIDString:deviceAddress]; NSArray * peripherals = [centralManager retrievePeripheralsWithIdentifiers:@[uuid]]; if ([peripherals count] != 1) { reject(@"unable_to_find_device", @"Could not find device with deviceAddress", nil); } else { CBPeripheral * peripheral = [peripherals objectAtIndex:0]; NSURL * url = [NSURL URLWithString:filePath]; DFUFirmware * firmware = [[DFUFirmware alloc] initWithUrlToZipFile:url]; DFUServiceInitiator * initiator = [[[DFUServiceInitiator alloc] initWithCentralManager:centralManager target:peripheral] withFirmware:firmware]; initiator.logger = self; initiator.delegate = self; initiator.progressDelegate = self; initiator.alternativeAdvertisingNameEnabled = alternativeAdvertisingNameEnabled; DFUServiceController * controller = [initiator start]; } } } } + (void)setCentralManagerGetter:(CBCentralManager * (^)())getter { getCentralManager = getter; } + (void)setOnDFUComplete:(void (^)())onComplete { onDFUComplete = onComplete; } + (void)setOnDFUError:(void (^)())onError { onDFUError = onError; } @end ================================================ FILE: ios/RNNordicDfu.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ B3E7B58A1CC2AC0600A0062D /* RNNordicDfu.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNNordicDfu.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ 58B511D91A9E6C8500147676 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = "include/$(PRODUCT_NAME)"; dstSubfolderSpec = 16; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ 134814201AA4EA6300B7C361 /* libRNNordicDfu.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNNordicDfu.a; sourceTree = BUILT_PRODUCTS_DIR; }; B3E7B5881CC2AC0600A0062D /* RNNordicDfu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNordicDfu.h; sourceTree = ""; }; B3E7B5891CC2AC0600A0062D /* RNNordicDfu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNordicDfu.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 58B511D81A9E6C8500147676 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 134814211AA4EA7D00B7C361 /* Products */ = { isa = PBXGroup; children = ( 134814201AA4EA6300B7C361 /* libRNNordicDfu.a */, ); name = Products; sourceTree = ""; }; 58B511D21A9E6C8500147676 = { isa = PBXGroup; children = ( B3E7B5881CC2AC0600A0062D /* RNNordicDfu.h */, B3E7B5891CC2AC0600A0062D /* RNNordicDfu.m */, 134814211AA4EA7D00B7C361 /* Products */, ); sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 58B511DA1A9E6C8500147676 /* RNNordicDfu */ = { isa = PBXNativeTarget; buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNNordicDfu" */; buildPhases = ( 58B511D71A9E6C8500147676 /* Sources */, 58B511D81A9E6C8500147676 /* Frameworks */, 58B511D91A9E6C8500147676 /* CopyFiles */, ); buildRules = ( ); dependencies = ( ); name = RNNordicDfu; productName = RCTDataManager; productReference = 134814201AA4EA6300B7C361 /* libRNNordicDfu.a */; productType = "com.apple.product-type.library.static"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 58B511D31A9E6C8500147676 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0610; ORGANIZATIONNAME = Facebook; TargetAttributes = { 58B511DA1A9E6C8500147676 = { CreatedOnToolsVersion = 6.1.1; }; }; }; buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNNordicDfu" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, ); mainGroup = 58B511D21A9E6C8500147676; productRefGroup = 58B511D21A9E6C8500147676; projectDirPath = ""; projectRoot = ""; targets = ( 58B511DA1A9E6C8500147676 /* RNNordicDfu */, ); }; /* End PBXProject section */ /* Begin PBXSourcesBuildPhase section */ 58B511D71A9E6C8500147676 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( B3E7B58A1CC2AC0600A0062D /* RNNordicDfu.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ 58B511ED1A9E6C8500147676 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; }; 58B511EE1A9E6C8500147676 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; }; 58B511F01A9E6C8500147676 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/**"; HEADER_SEARCH_PATHS = ( "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../../../React/**", "$(SRCROOT)/../../react-native/React/**", "$(PROJECT_DIR)/iOSDFULibrary.framework/**", "$(PROJECT_DIR)/../../../ios/Pods/Headers/Public/**", ); LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = RNNordicDfu; SKIP_INSTALL = YES; }; name = Debug; }; 58B511F11A9E6C8500147676 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/**"; HEADER_SEARCH_PATHS = ( "$(inherited)", /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, "$(SRCROOT)/../../../React/**", "$(SRCROOT)/../../react-native/React/**", "$(PROJECT_DIR)/iOSDFULibrary.framework/**", "$(PROJECT_DIR)/../../../ios/Pods/Headers/Public/**", ); LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = RNNordicDfu; SKIP_INSTALL = YES; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNNordicDfu" */ = { isa = XCConfigurationList; buildConfigurations = ( 58B511ED1A9E6C8500147676 /* Debug */, 58B511EE1A9E6C8500147676 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNNordicDfu" */ = { isa = XCConfigurationList; buildConfigurations = ( 58B511F01A9E6C8500147676 /* Debug */, 58B511F11A9E6C8500147676 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 58B511D31A9E6C8500147676 /* Project object */; } ================================================ FILE: package.json ================================================ { "name": "react-native-nordic-dfu", "version": "3.2.1", "description": "Nordic Device Firmware Update for React Native", "main": "index.js", "url": "https://github.com/Pilloxa/react-native-nordic-dfu", "repository": "Pilloxa/react-native-nordic-dfu", "scripts": { "test": "echo \"No test specified\"", "precommit": "lint-staged", "document": "documentation readme --readme-file README.md -s \"API\" -g" }, "keywords": [ "react-native", "dfu", "nordic" ], "author": "Pilloxa ", "license": "MIT", "peerDependencies": { "react-native": ">= 0.45.1" }, "devDependencies": { "documentation": "^4.0.0-rc.1", "husky": "^0.13.3", "lint-staged": "^3.4.0", "prettier": "^1.2.2" }, "lint-staged": { "*.js": [ "prettier --write", "git add" ], "index.js": [ "npm run document", "git add README.md" ] }, "types": "./index.d.ts" } ================================================ FILE: react-native-nordic-dfu.podspec ================================================ require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) Pod::Spec.new do |s| s.name = "react-native-nordic-dfu" s.version = package['version'] s.summary = package['description'] s.authors = { "Pilloxa" => "recruitment@pilloxa.com" } s.homepage = "https://github.com/Pilloxa/react-native-nordic-dfu" s.license = "Apache License 2.0" s.platform = :ios, "8.0" s.source = { :git => "https://github.com/Pilloxa/react-native-nordic-dfu.git" } s.source_files = "ios/**/*.{h,m}" s.dependency 'React' s.dependency 'iOSDFULibrary', '~> 4.11.1' end