diff --git a/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java b/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java index 6520122..e6216ca 100644 --- a/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java +++ b/android/src/main/java/com/pilloxa/dfu/RNNordicDfuModule.java @@ -38,7 +38,13 @@ public void startDFU(String address, String name, String filePath, Promise promi starter.setDeviceName(name); } starter.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true); - starter.setZip(filePath); + + if (filePath.endsWith(".bin") || filePath.endsWith(".hex")) { + starter.setBinOrHex(DfuBaseService.TYPE_APPLICATION, filePath).setInitFile(null, null); + } else { + starter.setZip(filePath); + } + final DfuServiceController controller = starter.start(this.reactContext, DfuService.class); } diff --git a/ios/RNNordicDfu.m b/ios/RNNordicDfu.m index ed58530..ebfda9e 100644 --- a/ios/RNNordicDfu.m +++ b/ios/RNNordicDfu.m @@ -213,10 +213,17 @@ - (void)logWith:(enum LogLevel)level message:(NSString * _Nonnull)message reject(@"unable_to_find_device", @"Could not find device with deviceAddress", nil); } else { CBPeripheral * peripheral = [peripherals objectAtIndex:0]; + DFUFirmware * firmware; NSURL * url = [NSURL URLWithString:filePath]; - - DFUFirmware * firmware = [[DFUFirmware alloc] initWithUrlToZipFile:url]; + NSString * extension = [url pathExtension]; + + if (([extension caseInsensitiveCompare:@"bin"] == NSOrderedSame) || + ([extension caseInsensitiveCompare:@"hex"] == NSOrderedSame)) { + firmware = [[DFUFirmware alloc] initWithUrlToBinOrHexFile:url urlToDatFile:nil type:4]; + } else { + firmware = [[DFUFirmware alloc] initWithUrlToZipFile:url]; + } DFUServiceInitiator * initiator = [[[DFUServiceInitiator alloc] initWithCentralManager:centralManager