@capgo/capacitor-updater 7.2.21 → 7.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ import Compression
15
15
  import UIKit
16
16
 
17
17
  @objc public class CapgoUpdater: NSObject {
18
+ private var logger: Logger!
18
19
 
19
20
  private let versionCode: String = Bundle.main.versionCode ?? ""
20
21
  private let versionOs = UIDevice.current.systemVersion
@@ -29,7 +30,6 @@ import UIKit
29
30
  // Add this line to declare cacheFolder
30
31
  private let cacheFolder: URL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("capgo_downloads")
31
32
 
32
- public static let TAG: String = "✨ Capacitor-updater:"
33
33
  public let CAP_SERVER_PATH: String = "serverBasePath"
34
34
  public var versionBuild: String = ""
35
35
  public var customId: String = ""
@@ -48,6 +48,10 @@ import UIKit
48
48
  }
49
49
  public var notifyDownload: (String, Int) -> Void = { _, _ in }
50
50
 
51
+ public func setLogger(_ logger: Logger) {
52
+ self.logger = logger
53
+ }
54
+
51
55
  private func calcTotalPercent(percent: Int, min: Int, max: Int) -> Int {
52
56
  return (percent * (max - min)) / 100 + min
53
57
  }
@@ -108,7 +112,7 @@ import UIKit
108
112
  do {
109
113
  try FileManager.default.createDirectory(atPath: source.path, withIntermediateDirectories: true, attributes: nil)
110
114
  } catch {
111
- print("\(CapgoUpdater.TAG) Cannot createDirectory \(source.path)")
115
+ logger.error("Cannot createDirectory \(source.path)")
112
116
  throw CustomError.cannotCreateDirectory
113
117
  }
114
118
  }
@@ -118,7 +122,7 @@ import UIKit
118
122
  do {
119
123
  try FileManager.default.removeItem(atPath: source.path)
120
124
  } catch {
121
- print("\(CapgoUpdater.TAG) File not removed. \(source.path)")
125
+ logger.error("File not removed. \(source.path)")
122
126
  throw CustomError.cannotDeleteDirectory
123
127
  }
124
128
  }
@@ -135,14 +139,14 @@ import UIKit
135
139
  return false
136
140
  }
137
141
  } catch {
138
- print("\(CapgoUpdater.TAG) File not moved. source: \(source.path) dest: \(dest.path)")
142
+ logger.error("File not moved. source: \(source.path) dest: \(dest.path)")
139
143
  throw CustomError.cannotUnflat
140
144
  }
141
145
  }
142
146
 
143
147
  private func unzipProgressHandler(entry: String, zipInfo: unz_file_info, entryNumber: Int, total: Int, destUnZip: URL, id: String, unzipError: inout NSError?) {
144
148
  if entry.contains("\\") {
145
- print("\(CapgoUpdater.TAG) unzip: Windows path is not supported, please use unix path as required by zip RFC: \(entry)")
149
+ logger.error("unzip: Windows path is not supported, please use unix path as required by zip RFC: \(entry)")
146
150
  self.sendStats(action: "windows_path_fail")
147
151
  }
148
152
 
@@ -245,7 +249,7 @@ import UIKit
245
249
  if let channel = channel {
246
250
  parameters.defaultChannel = channel
247
251
  }
248
- print("\(CapgoUpdater.TAG) Auto-update parameters: \(parameters)")
252
+ logger.info("Auto-update parameters: \(parameters)")
249
253
  let request = AF.request(url, method: .post, parameters: parameters, encoder: JSONParameterEncoder.default, requestModifier: { $0.timeoutInterval = self.timeout })
250
254
 
251
255
  request.validate().responseDecodable(of: AppVersionDec.self) { response in
@@ -279,7 +283,7 @@ import UIKit
279
283
  latest.manifest = manifest
280
284
  }
281
285
  case let .failure(error):
282
- print("\(CapgoUpdater.TAG) Error getting Latest", response.value ?? "", error )
286
+ self.logger.error("Error getting Latest \(response.value.debugDescription) \(error)")
283
287
  latest.message = "Error getting Latest \(String(describing: response.value))"
284
288
  latest.error = "response_error"
285
289
  }
@@ -292,7 +296,7 @@ import UIKit
292
296
  private func setCurrentBundle(bundle: String) {
293
297
  UserDefaults.standard.set(bundle, forKey: self.CAP_SERVER_PATH)
294
298
  UserDefaults.standard.synchronize()
295
- print("\(CapgoUpdater.TAG) Current bundle set to: \((bundle ).isEmpty ? BundleInfo.ID_BUILTIN : bundle)")
299
+ logger.info("Current bundle set to: \((bundle ).isEmpty ? BundleInfo.ID_BUILTIN : bundle)")
296
300
  }
297
301
 
298
302
  private var tempDataPath: URL {
@@ -311,7 +315,7 @@ import UIKit
311
315
 
312
316
  public func downloadManifest(manifest: [ManifestEntry], version: String, sessionKey: String) throws -> BundleInfo {
313
317
  let id = self.randomString(length: 10)
314
- print("\(CapgoUpdater.TAG) downloadManifest start \(id)")
318
+ logger.info("downloadManifest start \(id)")
315
319
  let destFolder = self.getBundleDirectory(id: id)
316
320
  let builtinFolder = Bundle.main.bundleURL.appendingPathComponent("public")
317
321
 
@@ -343,7 +347,7 @@ import UIKit
343
347
  fileHash = try CryptoCipherV2.decryptChecksum(checksum: fileHash, publicKey: self.publicKey)
344
348
  } catch {
345
349
  downloadError = error
346
- print("\(CapgoUpdater.TAG) CryptoCipherV2.decryptChecksum error \(id) \(fileName) error: \(error)")
350
+ logger.error("CryptoCipherV2.decryptChecksum error \(id) \(fileName) error: \(error)")
347
351
  }
348
352
  }
349
353
 
@@ -360,13 +364,13 @@ import UIKit
360
364
 
361
365
  if FileManager.default.fileExists(atPath: builtinFilePath.path) && verifyChecksum(file: builtinFilePath, expectedHash: fileHash) {
362
366
  try FileManager.default.copyItem(at: builtinFilePath, to: destFilePath)
363
- print("\(CapgoUpdater.TAG) downloadManifest \(fileName) using builtin file \(id)")
367
+ logger.info("downloadManifest \(fileName) using builtin file \(id)")
364
368
  completedFiles += 1
365
369
  self.notifyDownload(id: id, percent: self.calcTotalPercent(percent: Int((Double(completedFiles) / Double(totalFiles)) * 100), min: 10, max: 70))
366
370
  dispatchGroup.leave()
367
371
  } else if FileManager.default.fileExists(atPath: cacheFilePath.path) && verifyChecksum(file: cacheFilePath, expectedHash: fileHash) {
368
372
  try FileManager.default.copyItem(at: cacheFilePath, to: destFilePath)
369
- print("\(CapgoUpdater.TAG) downloadManifest \(fileName) copy from cache \(id)")
373
+ logger.info("downloadManifest \(fileName) copy from cache \(id)")
370
374
  completedFiles += 1
371
375
  self.notifyDownload(id: id, percent: self.calcTotalPercent(percent: Int((Double(completedFiles) / Double(totalFiles)) * 100), min: 10, max: 70))
372
376
  dispatchGroup.leave()
@@ -430,13 +434,13 @@ import UIKit
430
434
 
431
435
  completedFiles += 1
432
436
  self.notifyDownload(id: id, percent: self.calcTotalPercent(percent: Int((Double(completedFiles) / Double(totalFiles)) * 100), min: 10, max: 70))
433
- print("\(CapgoUpdater.TAG) downloadManifest \(id) \(fileName) downloaded\(isBrotli ? ", decompressed" : "")\(!self.publicKey.isEmpty && !sessionKey.isEmpty ? ", decrypted" : ""), and cached")
437
+ self.logger.info("downloadManifest \(id) \(fileName) downloaded\(isBrotli ? ", decompressed" : "")\(!self.publicKey.isEmpty && !sessionKey.isEmpty ? ", decrypted" : ""), and cached")
434
438
  } catch {
435
439
  downloadError = error
436
- NSLog("\(CapgoUpdater.TAG) downloadManifest \(id) \(fileName) error: \(error.localizedDescription)")
440
+ self.logger.error("downloadManifest \(id) \(fileName) error: \(error.localizedDescription)")
437
441
  }
438
442
  case .failure(let error):
439
- NSLog("\(CapgoUpdater.TAG) downloadManifest \(id) \(fileName) download error: \(error.localizedDescription). Debug response: \(response.debugDescription).")
443
+ self.logger.error("downloadManifest \(id) \(fileName) download error: \(error.localizedDescription). Debug response: \(response.debugDescription).")
440
444
  }
441
445
  }
442
446
  }
@@ -455,7 +459,7 @@ import UIKit
455
459
  let updatedBundle = bundleInfo.setStatus(status: BundleStatus.PENDING.localizedString)
456
460
  self.saveBundleInfo(id: id, bundle: updatedBundle)
457
461
 
458
- print("\(CapgoUpdater.TAG) downloadManifest done \(id)")
462
+ logger.info("downloadManifest done \(id)")
459
463
  return updatedBundle
460
464
  }
461
465
 
@@ -496,7 +500,7 @@ import UIKit
496
500
  var status = compression_stream_init(streamPointer, COMPRESSION_STREAM_DECODE, COMPRESSION_BROTLI)
497
501
 
498
502
  guard status != COMPRESSION_STATUS_ERROR else {
499
- print("\(CapgoUpdater.TAG) Error: Failed to initialize Brotli stream for \(fileName). Status: \(status)")
503
+ logger.error("Error: Failed to initialize Brotli stream for \(fileName). Status: \(status)")
500
504
  return nil
501
505
  }
502
506
 
@@ -518,7 +522,7 @@ import UIKit
518
522
  if let baseAddress = rawBufferPointer.baseAddress {
519
523
  streamPointer.pointee.src_ptr = baseAddress.assumingMemoryBound(to: UInt8.self)
520
524
  } else {
521
- print("\(CapgoUpdater.TAG) Error: Failed to get base address for \(fileName)")
525
+ logger.error("Error: Failed to get base address for \(fileName)")
522
526
  status = COMPRESSION_STATUS_ERROR
523
527
  return
524
528
  }
@@ -528,7 +532,7 @@ import UIKit
528
532
  if status == COMPRESSION_STATUS_ERROR {
529
533
  let maxBytes = min(32, data.count)
530
534
  let hexDump = data.prefix(maxBytes).map { String(format: "%02x", $0) }.joined(separator: " ")
531
- print("\(CapgoUpdater.TAG) Error: Brotli decompression failed for \(fileName). First \(maxBytes) bytes: \(hexDump)")
535
+ logger.error("Error: Brotli decompression failed for \(fileName). First \(maxBytes) bytes: \(hexDump)")
532
536
  break
533
537
  }
534
538
 
@@ -542,18 +546,18 @@ import UIKit
542
546
  if status == COMPRESSION_STATUS_END {
543
547
  break
544
548
  } else if status == COMPRESSION_STATUS_ERROR {
545
- print("\(CapgoUpdater.TAG) Error: Brotli process failed for \(fileName). Status: \(status)")
549
+ logger.error("Error: Brotli process failed for \(fileName). Status: \(status)")
546
550
  if let text = String(data: data, encoding: .utf8) {
547
551
  let asciiCount = text.unicodeScalars.filter { $0.isASCII }.count
548
552
  let totalCount = text.unicodeScalars.count
549
553
  if totalCount > 0 && Double(asciiCount) / Double(totalCount) >= 0.8 {
550
- print("\(CapgoUpdater.TAG) Error: Input appears to be plain text: \(text)")
554
+ logger.error("Error: Input appears to be plain text: \(text)")
551
555
  }
552
556
  }
553
557
 
554
558
  let maxBytes = min(32, data.count)
555
559
  let hexDump = data.prefix(maxBytes).map { String(format: "%02x", $0) }.joined(separator: " ")
556
- print("\(CapgoUpdater.TAG) Error: Raw data (\(fileName)): \(hexDump)")
560
+ logger.error("Error: Raw data (\(fileName)): \(hexDump)")
557
561
 
558
562
  return nil
559
563
  }
@@ -564,7 +568,7 @@ import UIKit
564
568
  }
565
569
 
566
570
  if input.count == 0 {
567
- print("\(CapgoUpdater.TAG) Error: Zero input size for \(fileName)")
571
+ logger.error("Error: Zero input size for \(fileName)")
568
572
  break
569
573
  }
570
574
  }
@@ -593,7 +597,7 @@ import UIKit
593
597
  let monitor = ClosureEventMonitor()
594
598
  monitor.requestDidCompleteTaskWithError = { (_, _, error) in
595
599
  if error != nil {
596
- print("\(CapgoUpdater.TAG) Downloading failed - ClosureEventMonitor activated")
600
+ self.logger.error("Downloading failed - ClosureEventMonitor activated")
597
601
  mainError = error as NSError?
598
602
  }
599
603
  }
@@ -624,11 +628,11 @@ import UIKit
624
628
  }
625
629
 
626
630
  } else {
627
- print("\(CapgoUpdater.TAG) Download failed")
631
+ self.logger.error("Download failed")
628
632
  }
629
633
 
630
634
  case .complete:
631
- print("\(CapgoUpdater.TAG) Download complete, total received bytes: \(totalReceivedBytes)")
635
+ self.logger.info("Download complete, total received bytes: \(totalReceivedBytes)")
632
636
  self.notifyDownload(id: id, percent: 70, ignoreMultipleOfTen: true)
633
637
  semaphore.signal()
634
638
  }
@@ -650,7 +654,7 @@ import UIKit
650
654
  reachabilityManager?.stopListening()
651
655
 
652
656
  if mainError != nil {
653
- print("\(CapgoUpdater.TAG) Failed to download: \(String(describing: mainError))")
657
+ logger.error("Failed to download: \(String(describing: mainError))")
654
658
  self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum))
655
659
  throw mainError!
656
660
  }
@@ -660,7 +664,7 @@ import UIKit
660
664
  try CryptoCipherV2.decryptFile(filePath: tempDataPath, publicKey: self.publicKey, sessionKey: sessionKey, version: version)
661
665
  try FileManager.default.moveItem(at: tempDataPath, to: finalPath)
662
666
  } catch {
663
- print("\(CapgoUpdater.TAG) Failed decrypt file : \(error)")
667
+ logger.error("Failed decrypt file : \(error)")
664
668
  self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum))
665
669
  cleanDownloadData()
666
670
  throw error
@@ -668,11 +672,11 @@ import UIKit
668
672
 
669
673
  do {
670
674
  checksum = CryptoCipherV2.calcChecksum(filePath: finalPath)
671
- print("\(CapgoUpdater.TAG) Downloading: 80% (unzipping)")
675
+ logger.info("Downloading: 80% (unzipping)")
672
676
  try self.saveDownloaded(sourceZip: finalPath, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: true)
673
677
 
674
678
  } catch {
675
- print("\(CapgoUpdater.TAG) Failed to unzip file: \(error)")
679
+ logger.error("Failed to unzip file: \(error)")
676
680
  self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum))
677
681
  cleanDownloadData()
678
682
  // todo: cleanup zip attempts
@@ -680,25 +684,25 @@ import UIKit
680
684
  }
681
685
 
682
686
  self.notifyDownload(id: id, percent: 90)
683
- print("\(CapgoUpdater.TAG) Downloading: 90% (wrapping up)")
687
+ logger.info("Downloading: 90% (wrapping up)")
684
688
  let info = BundleInfo(id: id, version: version, status: BundleStatus.PENDING, downloaded: Date(), checksum: checksum)
685
689
  self.saveBundleInfo(id: id, bundle: info)
686
690
  self.cleanDownloadData()
687
691
  self.notifyDownload(id: id, percent: 100)
688
- print("\(CapgoUpdater.TAG) Downloading: 100% (complete)")
692
+ logger.info("Downloading: 100% (complete)")
689
693
  return info
690
694
  }
691
695
  private func ensureResumableFilesExist() {
692
696
  let fileManager = FileManager.default
693
697
  if !fileManager.fileExists(atPath: tempDataPath.path) {
694
698
  if !fileManager.createFile(atPath: tempDataPath.path, contents: Data()) {
695
- print("\(CapgoUpdater.TAG) Cannot ensure that a file at \(tempDataPath.path) exists")
699
+ logger.error("Cannot ensure that a file at \(tempDataPath.path) exists")
696
700
  }
697
701
  }
698
702
 
699
703
  if !fileManager.fileExists(atPath: updateInfo.path) {
700
704
  if !fileManager.createFile(atPath: updateInfo.path, contents: Data()) {
701
- print("\(CapgoUpdater.TAG) Cannot ensure that a file at \(updateInfo.path) exists")
705
+ logger.error("Cannot ensure that a file at \(updateInfo.path) exists")
702
706
  }
703
707
  }
704
708
  }
@@ -710,7 +714,7 @@ import UIKit
710
714
  do {
711
715
  try fileManager.removeItem(at: tempDataPath)
712
716
  } catch {
713
- print("\(CapgoUpdater.TAG) Could not delete file at \(tempDataPath): \(error)")
717
+ logger.error("Could not delete file at \(tempDataPath): \(error)")
714
718
  }
715
719
  }
716
720
  // Deleting update.dat
@@ -718,7 +722,7 @@ import UIKit
718
722
  do {
719
723
  try fileManager.removeItem(at: updateInfo)
720
724
  } catch {
721
- print("\(CapgoUpdater.TAG) Could not delete file at \(updateInfo): \(error)")
725
+ logger.error("Could not delete file at \(updateInfo): \(error)")
722
726
  }
723
727
  }
724
728
  }
@@ -737,7 +741,7 @@ import UIKit
737
741
  fileHandle.closeFile()
738
742
  }
739
743
  } catch {
740
- print("Failed to write data starting at byte \(byteOffset): \(error)")
744
+ logger.error("Failed to write data starting at byte \(byteOffset): \(error)")
741
745
  }
742
746
  self.tempData.removeAll() // Clearing tempData to avoid writing the same data multiple times
743
747
  }
@@ -746,7 +750,7 @@ import UIKit
746
750
  do {
747
751
  try "\(version)".write(to: updateInfo, atomically: true, encoding: .utf8)
748
752
  } catch {
749
- print("\(CapgoUpdater.TAG) Failed to save progress: \(error)")
753
+ logger.error("Failed to save progress: \(error)")
750
754
  }
751
755
  }
752
756
  private func getLocalUpdateVersion() -> String { // Return the version that was tried to be downloaded on last download attempt
@@ -768,7 +772,7 @@ import UIKit
768
772
  return fileSize.int64Value
769
773
  }
770
774
  } catch {
771
- print("\(CapgoUpdater.TAG) Could not retrieve already downloaded data size : \(error)")
775
+ logger.error("Could not retrieve already downloaded data size : \(error)")
772
776
  }
773
777
  return 0
774
778
  }
@@ -780,7 +784,7 @@ import UIKit
780
784
  do {
781
785
  let files: [String] = try FileManager.default.contentsOfDirectory(atPath: dest.path)
782
786
  var res: [BundleInfo] = []
783
- print("\(CapgoUpdater.TAG) list File : \(dest.path)")
787
+ logger.info("list File : \(dest.path)")
784
788
  if dest.exist {
785
789
  for id: String in files {
786
790
  res.append(self.getBundleInfo(id: id))
@@ -788,12 +792,12 @@ import UIKit
788
792
  }
789
793
  return res
790
794
  } catch {
791
- print("\(CapgoUpdater.TAG) No version available \(dest.path)")
795
+ logger.info("No version available \(dest.path)")
792
796
  return []
793
797
  }
794
798
  } else {
795
799
  guard let regex = try? NSRegularExpression(pattern: "^[0-9A-Za-z]{10}_info$") else {
796
- print("\(CapgoUpdater.TAG) Invald regex ?????")
800
+ logger.error("Invalid regex ?????")
797
801
  return []
798
802
  }
799
803
  return UserDefaults.standard.dictionaryRepresentation().keys.filter {
@@ -812,7 +816,7 @@ import UIKit
812
816
  public func delete(id: String, removeInfo: Bool) -> Bool {
813
817
  let deleted: BundleInfo = self.getBundleInfo(id: id)
814
818
  if deleted.isBuiltin() || self.getCurrentBundleId() == id {
815
- print("\(CapgoUpdater.TAG) Cannot delete \(id)")
819
+ logger.info("Cannot delete \(id)")
816
820
  return false
817
821
  }
818
822
 
@@ -821,7 +825,7 @@ import UIKit
821
825
  !next.isDeleted() &&
822
826
  !next.isErrorStatus() &&
823
827
  next.getId() == id {
824
- print("\(CapgoUpdater.TAG) Cannot delete the next bundle \(id)")
828
+ logger.info("Cannot delete the next bundle \(id)")
825
829
  return false
826
830
  }
827
831
 
@@ -829,7 +833,7 @@ import UIKit
829
833
  do {
830
834
  try FileManager.default.removeItem(atPath: destPersist.path)
831
835
  } catch {
832
- print("\(CapgoUpdater.TAG) Folder \(destPersist.path), not removed.")
836
+ logger.error("Folder \(destPersist.path), not removed.")
833
837
  // even if, we don;t care. Android doesn't care
834
838
  if removeInfo {
835
839
  self.removeBundleInfo(id: id)
@@ -842,7 +846,7 @@ import UIKit
842
846
  } else {
843
847
  self.saveBundleInfo(id: id, bundle: deleted.setStatus(status: BundleStatus.DELETED.localizedString))
844
848
  }
845
- print("\(CapgoUpdater.TAG) bundle delete \(deleted.getVersionName())")
849
+ logger.info("bundle delete \(deleted.getVersionName())")
846
850
  self.sendStats(action: "delete", versionName: deleted.getVersionName())
847
851
  return true
848
852
  }
@@ -895,7 +899,7 @@ import UIKit
895
899
  public func autoReset() {
896
900
  let currentBundle: BundleInfo = self.getCurrentBundle()
897
901
  if !currentBundle.isBuiltin() && !self.bundleExists(id: currentBundle.getId()) {
898
- print("\(CapgoUpdater.TAG) Folder at bundle path does not exist. Triggering reset.")
902
+ logger.info("Folder at bundle path does not exist. Triggering reset.")
899
903
  self.reset()
900
904
  }
901
905
  }
@@ -905,7 +909,7 @@ import UIKit
905
909
  }
906
910
 
907
911
  public func reset(isInternal: Bool) {
908
- print("\(CapgoUpdater.TAG) reset: \(isInternal)")
912
+ logger.info("reset: \(isInternal)")
909
913
  let currentBundleName = self.getCurrentBundle().getVersionName()
910
914
  self.setCurrentBundle(bundle: "")
911
915
  self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
@@ -918,14 +922,14 @@ import UIKit
918
922
  public func setSuccess(bundle: BundleInfo, autoDeletePrevious: Bool) {
919
923
  self.setBundleStatus(id: bundle.getId(), status: BundleStatus.SUCCESS)
920
924
  let fallback: BundleInfo = self.getFallbackBundle()
921
- print("\(CapgoUpdater.TAG) Fallback bundle is: \(fallback.toString())")
922
- print("\(CapgoUpdater.TAG) Version successfully loaded: \(bundle.toString())")
925
+ logger.info("Fallback bundle is: \(fallback.toString())")
926
+ logger.info("Version successfully loaded: \(bundle.toString())")
923
927
  if autoDeletePrevious && !fallback.isBuiltin() && fallback.getId() != bundle.getId() {
924
928
  let res = self.delete(id: fallback.getId())
925
929
  if res {
926
- print("\(CapgoUpdater.TAG) Deleted previous bundle: \(fallback.toString())")
930
+ logger.info("Deleted previous bundle: \(fallback.toString())")
927
931
  } else {
928
- print("\(CapgoUpdater.TAG) Failed to delete previous bundle: \(fallback.toString())")
932
+ logger.error("Failed to delete previous bundle: \(fallback.toString())")
929
933
  }
930
934
  }
931
935
  self.setFallbackBundle(fallback: bundle)
@@ -938,7 +942,7 @@ import UIKit
938
942
  func unsetChannel() -> SetChannel {
939
943
  let setChannel: SetChannel = SetChannel()
940
944
  if (self.channelUrl ).isEmpty {
941
- print("\(CapgoUpdater.TAG) Channel URL is not set")
945
+ logger.error("Channel URL is not set")
942
946
  setChannel.message = "Channel URL is not set"
943
947
  setChannel.error = "missing_config"
944
948
  return setChannel
@@ -961,7 +965,7 @@ import UIKit
961
965
  setChannel.message = message
962
966
  }
963
967
  case let .failure(error):
964
- print("\(CapgoUpdater.TAG) Error unset Channel", response.value ?? "", error)
968
+ self.logger.error("Error unset Channel \(response.value.debugDescription) \(error)")
965
969
  setChannel.message = "Error unset Channel \(String(describing: response.value))"
966
970
  setChannel.error = "response_error"
967
971
  }
@@ -974,7 +978,7 @@ import UIKit
974
978
  func setChannel(channel: String) -> SetChannel {
975
979
  let setChannel: SetChannel = SetChannel()
976
980
  if (self.channelUrl ).isEmpty {
977
- print("\(CapgoUpdater.TAG) Channel URL is not set")
981
+ logger.error("Channel URL is not set")
978
982
  setChannel.message = "Channel URL is not set"
979
983
  setChannel.error = "missing_config"
980
984
  return setChannel
@@ -998,7 +1002,7 @@ import UIKit
998
1002
  setChannel.message = message
999
1003
  }
1000
1004
  case let .failure(error):
1001
- print("\(CapgoUpdater.TAG) Error set Channel", response.value ?? "", error)
1005
+ self.logger.error("Error set Channel \(response.value.debugDescription) \(error)")
1002
1006
  setChannel.message = "Error set Channel \(String(describing: response.value))"
1003
1007
  setChannel.error = "response_error"
1004
1008
  }
@@ -1011,7 +1015,7 @@ import UIKit
1011
1015
  func getChannel() -> GetChannel {
1012
1016
  let getChannel: GetChannel = GetChannel()
1013
1017
  if (self.channelUrl ).isEmpty {
1014
- print("\(CapgoUpdater.TAG) Channel URL is not set")
1018
+ logger.error("Channel URL is not set")
1015
1019
  getChannel.message = "Channel URL is not set"
1016
1020
  getChannel.error = "missing_config"
1017
1021
  return getChannel
@@ -1050,7 +1054,7 @@ import UIKit
1050
1054
  }
1051
1055
  }
1052
1056
 
1053
- print("\(CapgoUpdater.TAG) Error get Channel", response.value ?? "", error)
1057
+ self.logger.error("Error get Channel \(response.value.debugDescription) \(error)")
1054
1058
  getChannel.message = "Error get Channel \(String(describing: response.value)))"
1055
1059
  getChannel.error = "response_error"
1056
1060
  }
@@ -1085,9 +1089,9 @@ import UIKit
1085
1089
  ).responseData { response in
1086
1090
  switch response.result {
1087
1091
  case .success:
1088
- print("\(CapgoUpdater.TAG) Stats sent for \(action), version \(versionName)")
1092
+ self.logger.info("Stats sent for \(action), version \(versionName)")
1089
1093
  case let .failure(error):
1090
- print("\(CapgoUpdater.TAG) Error sending stats: ", response.value ?? "", error.localizedDescription)
1094
+ self.logger.error("Error sending stats: \(response.value?.debugDescription ?? "") \(error.localizedDescription)")
1091
1095
  }
1092
1096
  semaphore.signal()
1093
1097
  }
@@ -1102,7 +1106,6 @@ import UIKit
1102
1106
  if id != nil {
1103
1107
  trueId = id!
1104
1108
  }
1105
- // print("\(CapgoUpdater.TAG) Getting info for bundle [\(trueId)]")
1106
1109
  let result: BundleInfo
1107
1110
  if BundleInfo.ID_BUILTIN == trueId {
1108
1111
  result = BundleInfo(id: trueId, version: "", status: BundleStatus.SUCCESS, checksum: "")
@@ -1112,11 +1115,10 @@ import UIKit
1112
1115
  do {
1113
1116
  result = try UserDefaults.standard.getObj(forKey: "\(trueId)\(self.INFO_SUFFIX)", castTo: BundleInfo.self)
1114
1117
  } catch {
1115
- print("\(CapgoUpdater.TAG) Failed to parse info for bundle [\(trueId)]", error.localizedDescription)
1118
+ logger.error("Failed to parse info for bundle [\(trueId)] \(error.localizedDescription)")
1116
1119
  result = BundleInfo(id: trueId, version: "", status: BundleStatus.PENDING, checksum: "")
1117
1120
  }
1118
1121
  }
1119
- // print("\(CapgoUpdater.TAG) Returning info bundle [\(result.toString())]")
1120
1122
  return result
1121
1123
  }
1122
1124
 
@@ -1136,26 +1138,26 @@ import UIKit
1136
1138
 
1137
1139
  public func saveBundleInfo(id: String, bundle: BundleInfo?) {
1138
1140
  if bundle != nil && (bundle!.isBuiltin() || bundle!.isUnknown()) {
1139
- print("\(CapgoUpdater.TAG) Not saving info for bundle [\(id)]", bundle?.toString() ?? "")
1141
+ logger.info("Not saving info for bundle [\(id)] \(bundle?.toString() ?? "")")
1140
1142
  return
1141
1143
  }
1142
1144
  if bundle == nil {
1143
- print("\(CapgoUpdater.TAG) Removing info for bundle [\(id)]")
1145
+ logger.info("Removing info for bundle [\(id)]")
1144
1146
  UserDefaults.standard.removeObject(forKey: "\(id)\(self.INFO_SUFFIX)")
1145
1147
  } else {
1146
1148
  let update = bundle!.setId(id: id)
1147
- print("\(CapgoUpdater.TAG) Storing info for bundle [\(id)]", update.toString())
1149
+ logger.info("Storing info for bundle [\(id)] \(update.toString())")
1148
1150
  do {
1149
1151
  try UserDefaults.standard.setObj(update, forKey: "\(id)\(self.INFO_SUFFIX)")
1150
1152
  } catch {
1151
- print("\(CapgoUpdater.TAG) Failed to save info for bundle [\(id)]", error.localizedDescription)
1153
+ logger.error("Failed to save info for bundle [\(id)] \(error.localizedDescription)")
1152
1154
  }
1153
1155
  }
1154
1156
  UserDefaults.standard.synchronize()
1155
1157
  }
1156
1158
 
1157
1159
  private func setBundleStatus(id: String, status: BundleStatus) {
1158
- print("\(CapgoUpdater.TAG) Setting status for bundle [\(id)] to \(status)")
1160
+ logger.info("Setting status for bundle [\(id)] to \(status)")
1159
1161
  let info = self.getBundleInfo(id: id)
1160
1162
  self.saveBundleInfo(id: id, bundle: info.setStatus(status: status.localizedString))
1161
1163
  }