Skip to content

Commit e108e7f

Browse files
feat(ios): add DFU logging via os.Logger (#5)
Implement LoggerDelegate to forward Nordic DFU library log messages to the unified os.Logger system. Logs are visible in Xcode console and Console.app, filterable by subsystem (community.capacitor.nordic-dfu).
1 parent 444d056 commit e108e7f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ios/Plugin/Plugin.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import Capacitor
22
import NordicDFU
33
import CoreBluetooth
44
import Foundation
5+
import os
56
import UserNotifications
67

78
@objc(NordicDfuPlugin)
8-
public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDelegate, DFUProgressDelegate, NotificationHandlerProtocol {
9+
public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDelegate, DFUProgressDelegate, LoggerDelegate, NotificationHandlerProtocol {
910
public var dfuChangeEvent: String = "DFUStateChanged"
1011
var notificationRequestLookup = [String: JSObject]()
1112
private var manager: CBCentralManager?
1213
private var dfuStartTime: TimeInterval?
14+
private let logger = Logger(subsystem: "community.capacitor.nordic-dfu", category: "DFU")
1315

1416
override public func load() {
1517
manager = CBCentralManager(delegate: self, queue: nil)
@@ -325,6 +327,7 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel
325327
let peripheral = peripherals[0]
326328
starter.delegate = self
327329
starter.progressDelegate = self
330+
starter.logger = self
328331
_ = starter.start(target: peripheral)
329332

330333
call.resolve()
@@ -365,4 +368,17 @@ public class NordicDfuPlugin: CAPPlugin, CBCentralManagerDelegate, DFUServiceDel
365368
call.resolve(["notifications": permission])
366369
}
367370
}
371+
372+
public func logWith(_ level: LogLevel, message: String) {
373+
switch level {
374+
case .debug, .verbose:
375+
logger.debug("\(message, privacy: .public)")
376+
case .info, .application:
377+
logger.info("\(message, privacy: .public)")
378+
case .warning:
379+
logger.warning("\(message, privacy: .public)")
380+
case .error:
381+
logger.error("\(message, privacy: .public)")
382+
}
383+
}
368384
}

0 commit comments

Comments
 (0)