### Install NordicDFU with Cocoapods Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/README.md Add the NordicDFU pod to your Podfile and run 'pod install'. Import the library using 'import NordicDFU'. ```ruby target 'YourAppTargetName' do use_frameworks! pod 'NordicDFU' end ``` ```shell pod install ``` -------------------------------- ### Install Cocoapods Dependencies Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/README_OBJC.md Run this command in your project directory after updating the Podfile to install the specified dependencies. ```bash pod install ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/README.md Ensure you have the latest version of the Xcode command line tools installed before proceeding with fastlane installation. ```shell xcode-select --install ``` -------------------------------- ### Install NordicDFU with Carthage Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/README.md Create a Cartfile with the repository URL and version, then run 'carthage update --use-xcframeworks --platform iOS'. ```shell carthage update --use-xcframeworks --platform iOS ``` -------------------------------- ### Initialize DFU Process Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Library/Classes/Documentation.docc/Documentation.md Use DFUServiceInitiator to set up and start the DFU process with a target peripheral and selected firmware. Delegates and logger can be optionally configured. ```swift let initiator = DFUServiceInitiator() // Optional: // initiator.forceDfu = true/false // default false // initiator.packetReceiptNotificationParameter = N // default is 12 initiator.logger = self // - to get log info initiator.delegate = self // - to be informed about current state and errors initiator.progressDelegate = self // - to get progress updates // initiator.peripheralSelector = ... // the default selector is used let controller = initiator.with(firmware: selectedFirmware).start(target: peripheral) ``` -------------------------------- ### Carthage Installation Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Integrate ZIPFoundation into your Xcode project using Carthage by adding it to your Cartfile. ```ogdl github "weichsel/ZIPFoundation" ~> 0.9 ``` -------------------------------- ### CocoaPods Installation Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Add ZIPFoundation to your project's Podfile for integration using CocoaPods. ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks! target '' do pod 'ZIPFoundation', '~> 0.9' end ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Add ZIPFoundation as a dependency in your Package.swift file for Swift Package Manager integration. ```swift // swift-tools-version:5.0 import PackageDescription let package = Package( name: "", dependencies: [ .package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0")) ], targets: [ .target( name: "", dependencies: ["ZIPFoundation"]) ] ) ``` -------------------------------- ### Install NordicDFU with Swift Package Manager Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/README.md Add the NordicDFU library as a dependency in your Swift Package Manager configuration. ```swift // swift-tools-version:5.6 import PackageDescription let package = Package( name: "", dependencies: [ .package( url: "https://github.com/NordicSemiconductor/IOS-DFU-Library", .upToNextMajor(from: "") ) ], targets: [.target(name: "", dependencies: ["NordicDFU"])] ) ``` -------------------------------- ### Import NordicDFU Library in Obj-C Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/README_OBJC.md After successful installation and build, import the NordicDFU library into your Objective-C classes using the '@import' directive. ```objective-c @import NordicDFU; ``` -------------------------------- ### Run fastlane iOS Screenshots Action Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/README.md Execute the fastlane command to generate new localized screenshots for your iOS application. The `bundle exec` prefix is optional and depends on your project setup. ```shell [bundle exec] fastlane ios screenshots ``` -------------------------------- ### Get Current Tab Function Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Retrieves the index of the currently active tab. Defaults to tab 1 if no active tab is found. ```javascript function getCurrentTab() { var i, tabs; tabs = document.getElementsByClassName("tabContent"); for (i = 0; i < tabs.length; i++) { if (tabs[i].style.display != "none") { return i + 1; } } return 1; // fallback } ``` -------------------------------- ### Simulate Click Event Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Dispatches a click event on a given HTML element. This is used to programmatically trigger click actions, for example, when opening a default tab. ```javascript function doClick(el) { if (document.createEvent) { var evObj = document.createEvent('MouseEvents', true); evObj.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); el.dispatchEvent(evObj); } else if (document.createEventObject) { //IE var evObj = document.createEventObject(); el.fireEvent('onclick', evObj); } } ``` -------------------------------- ### Create DFUFirmware Object from ZIP Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Library/Classes/Documentation.docc/Documentation.md Initialize a DFUFirmware object using a URL to a distribution packet (ZIP) file. This is the recommended method for updating firmware. ```swift let selectedFirmware = try DFUFirmware(urlToZipFile: url) ``` -------------------------------- ### Create DFUFirmware Object from BIN/HEX Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Library/Classes/Documentation.docc/Documentation.md Initialize a DFUFirmware object using URLs to BIN/HEX and optionally DAT files, specifying the firmware type. Use this for individual firmware components. ```swift let selectedFirmware = try DFUFirmware(urlToBinOrHexFile: url, urlToDatFile: datUrl, type: .application) ``` -------------------------------- ### Display ZIP Package Contents with nrfutil Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Sources/Firmwares/Readme.md Demonstrates how to use the nrfutil command-line tool to display the contents of a ZIP package, specifically decoding init packets. ```bash nrfutil pkg display [file_name.zip] ``` -------------------------------- ### Initialize Screenshot Display Logic Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Sets up the initial state and event listeners for screenshot interactions when the page loads. It hides tab titles and shows a sort menu, then triggers a click on the default tab. ```javascript var overlay = document.getElementById('overlay'); var imageDisplay = document.getElementById('imageDisplay'); var imageInfo = document.getElementById('imageInfo'); var screenshotLink = document.getElementsByClassName('screenshotLink'); window.onload = setup(); function setup() { var i, menu, tabTitles; // Since JS is enabled, show sort menu and hide tab titles menu = document.getElementById("sortMenu"); menu.style.display = "block"; tabTitles = document.getElementsByClassName("tabTitle"); for (i = 0; i < tabTitles.length; i++) { tabTitles[i].style.display = "none"; } doClick(document.getElementById("defaultTab")); } ``` -------------------------------- ### Add Entry from File Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Adds an entry to a ZIP archive from an existing file using a relative path and base URL. Ensure the archive is opened in `.update` mode. ```swift let fileManager = FileManager() let currentWorkingPath = fileManager.currentDirectoryPath var archiveURL = URL(fileURLWithPath: currentWorkingPath) archiveURL.appendPathComponent("archive.zip") guard let archive = Archive(url: archiveURL, accessMode: .update) else { return } var fileURL = URL(fileURLWithPath: currentWorkingPath) fileURL.appendPathComponent("file.txt") do { try archive.addEntry(with: fileURL.lastPathComponent, relativeTo: fileURL.deletingLastPathComponent()) } catch { print("Adding entry to ZIP archive failed with error:\(error)") } ``` -------------------------------- ### Create a New Archive Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Creates a new, empty ZIP archive at the specified file URL using the .create access mode. ```swift let currentWorkingPath = fileManager.currentDirectoryPath var archiveURL = URL(fileURLWithPath: currentWorkingPath) archiveURL.appendPathComponent("newArchive.zip") guard let archive = Archive(url: archiveURL, accessMode: .create) else { return } ``` -------------------------------- ### SDK Version Formatting Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Sources/Firmwares/Readme.md Explains how the SDK version is represented in the DFU device name, without a decimal point. ```text 141 = SDK 14.1, 08 = SDK 8, 061 = SDK 6.1 ``` -------------------------------- ### Cocoapods Podfile Configuration for Obj-C Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/README_OBJC.md Configure your Podfile to include the NordicDFU library for your Objective-C application target. Ensure 'use_frameworks!' is set. ```ruby target 'YourAppTargetName' do use_frameworks! pod 'NordicDFU' end ``` -------------------------------- ### Create In-Memory Archive Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Creates a ZIP archive that resides entirely in memory. This is useful for dynamically generating archives to be sent over a network without disk I/O. ```swift let string = "Some string!" guard let archive = Archive(accessMode: .create), let data = string.data(using: .utf8) else { return } try? archive.addEntry(with: "inMemory.txt", type: .file, uncompressedSize: UInt64(data.count), bufferSize: 4, provider: { (position, size) -> Data in return data.subdata(in: position.. Data in // This will be called until `data` is exhausted (3x in this case). return data.subdata(in: position.. ``` -------------------------------- ### Open Tab Functionality Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Handles switching between different tabs. It hides all tab content, removes the 'active' class from all tab links, and then displays the content of the selected tab and marks its link as active. ```javascript function openTab(evt, tabName) { var i, tabContent, tabLinks; tabs = document.getElementsByClassName("tabContent"); for (i = 0; i < tabs.length; i++) { tabs[i].style.display = "none"; } tabLinks = document.getElementsByClassName("tabLink"); for (i = 0; i < tabLinks.length; i++) { tabLinks[i].className = tabLinks[i].className.replace(" active", ""); } document.getElementById(tabName).style.display = "block"; evt.currentTarget.className += " active"; } ``` -------------------------------- ### Image Display Click Listener Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Handles clicks on the displayed image within the overlay. It attempts to navigate to the next or first screenshot in the current tab based on the image's counter data attribute. ```javascript imageDisplay.addEventListener('click', function(e) { e.stopPropagation(); // ! overlay.style.display = "none"; img_tab = parseInt(getCurrentTab()); img_counter = parseInt(e.target.dataset.counter) + 1; try { link = document.body.querySelector('img[data-tab="'+img_tab+'"] [data-counter="'+img_counter+'"] ').parentNode; } catch (e) { try { link = document.body.querySelector('img[data-tab="'+img_tab+'"] [data-counter="0"] ').parentNode; } catch (e) { return false; } } doClick(link); }); ``` -------------------------------- ### Extract Entry with Consumer Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Extracts the contents of a ZIP entry using a closure-based consumer. The consumer is called repeatedly with chunks of data until the entry is fully read. ```swift try archive.extract(entry, consumer: { (data) in print(data.count) }) ``` -------------------------------- ### Access and Extract Individual Entry from Archive Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Accesses a specific entry within a ZIP archive by its relative path and extracts it to a destination URL. ```swift let fileManager = FileManager() let currentWorkingPath = fileManager.currentDirectoryPath var archiveURL = URL(fileURLWithPath: currentWorkingPath) archiveURL.appendPathComponent("archive.zip") guard let archive = Archive(url: archiveURL, accessMode: .read) else { return } guard let entry = archive["file.txt"] else { return } var destinationURL = URL(fileURLWithPath: currentWorkingPath) destinationURL.appendPathComponent("out.txt") do { try archive.extract(entry, to: destinationURL) } catch { print("Extracting entry from archive failed with error:\(error)") } ``` -------------------------------- ### Zip a Single File Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Zips a single file to a destination URL. Ensure the source and destination URLs are valid. ```swift let fileManager = FileManager() let currentWorkingPath = fileManager.currentDirectoryPath var sourceURL = URL(fileURLPathComponent: currentWorkingPath) sourceURL.appendPathComponent("file.txt") var destinationURL = URL(fileURLWithPath: currentWorkingPath) destinationURL.appendPathComponent("archive.zip") do { try fileManager.zipItem(at: sourceURL, to: destinationURL) } catch { print("Creation of ZIP archive failed with error:\(error)") } ``` -------------------------------- ### Screenshot Click Event Listener Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Attaches a click event listener to elements with the class 'screenshotLink'. When clicked, it prevents the default action, determines the target image, and adjusts the display size of the image preview based on viewport dimensions before showing an overlay. ```javascript for (index = 0; index < screenshotLink.length; ++index) { screenshotLink[index].addEventListener('click', function(e) { e.preventDefault(); var img = e.target; if (e.target.tagName == 'A') { img = e.target.children[0]; } // beautify var tmpImg = new Image(); tmpImg.src = img.src; imageDisplay.style.height = 'auto'; imageDisplay.style.width = 'auto'; imageDisplay.style.paddingTop = 0; if (window.innerHeight < tmpImg.height) { imageDisplay.style.height = document.documentElement.clientHeight+'px'; } else if (window.innerWidth < tmpImg.width) { imageDisplay.style.width = document.documentElement.clientWidth;+'px'; } else { imageDisplay.style.paddingTop = parseInt((window.innerHeight - tmpImg.height) / 2)+'px'; } imageDisplay.src = img.src; imageDisplay.alt = img.alt; imageDisplay.dataset.counter = img.dataset.counter; imageInfo.innerHTML = '

'+img.alt+'

'; imageInfo.innerHTML += decodeURI(img.src.split("/").pop()); imageInfo.innerHTML += '
'+tmpImg.height+'×'+tmpImg.width+'px'; overlay.style.display = "block"; }); } ``` -------------------------------- ### Keyboard Input Handling Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Processes keyboard events, specifically handling the Escape key to close the overlay, and Page Down, Right Arrow, or specific numeric keys to navigate to the next screenshot. ```javascript function keyPressed(e) { e = e || window.event; var charCode = e.keyCode || e.which; switch(charCode) { case 27: // Esc overlay.style.display = "none"; break; case 34: // Page Down case 39: // Right arrow case 54: // Keypad right case 76: // l case 102: // Keypad right e.preventDefault(); doClick(imageDisplay); break; ca ``` -------------------------------- ### Keyboard Event Listener for Image Display Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html This JavaScript code sets up a keyboard event listener to modify a counter associated with an image display element and trigger a click action. It handles specific key codes for navigation or control. ```javascript document.getElementById('imageDisplay').dataset.counter -= 2; // hacky doClick(imageDisplay); break; } }; document.body.addEventListener('keydown', keyPressed); ``` -------------------------------- ### Overlay Click Listener Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/App/fastlane/screenshots/screenshots.html Hides the screenshot overlay when the overlay itself is clicked. ```javascript overlay.addEventListener('click', function(e) { overlay.style.display = "none"; }) ``` -------------------------------- ### Remove Entry from Archive Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Pods/ZIPFoundation/README.md Removes a specific entry from a ZIP archive. Requires a reference to the entry object obtained by accessing the archive. ```swift guard let entry = archive["file.txt"] else { return } do { try archive.remove(entry) } catch { print("Removing entry from ZIP archive failed with error:\(error)") } ``` -------------------------------- ### Board ID Mapping Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Sources/Firmwares/Readme.md Defines the mapping between numerical Board IDs and the corresponding nRF chip models. ```text 1 = nRF51 2 = nRF52832 3 = nRF52840 ``` -------------------------------- ### DFU Mode Mapping Source: https://github.com/nordicsemiconductor/ios-dfu-library/blob/main/Test App/Sources/Firmwares/Readme.md Defines the mapping between the mode character and its meaning in the DFU device name. ```text A = Application B = Bootloader ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.