From 14bbbd29bf3b38f2c7242ff4de9a2cdcfd8dbb48 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 24 Feb 2017 14:19:32 -0500 Subject: [PATCH] Cellular capability detection --- Kiwix-iOS/iOSExtensions.swift | 16 ++++++++++++++++ Kiwix/Kiwix-Bridging-Header.h | 1 + Kiwix/Operations/UIProcedure.swift | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Kiwix-iOS/iOSExtensions.swift b/Kiwix-iOS/iOSExtensions.swift index 1cd49ffa..70c1303a 100644 --- a/Kiwix-iOS/iOSExtensions.swift +++ b/Kiwix-iOS/iOSExtensions.swift @@ -60,3 +60,19 @@ extension Bundle { return (Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String) ?? "Unknown" } } + +extension UIDevice { + class var hasCellularCapability: Bool { + // Get list of all interfaces on the local machine: + var ifaddr : UnsafeMutablePointer? = nil + if getifaddrs(&ifaddr) == 0 { + var ptr = ifaddr + while ptr != nil { + ptr = ptr!.pointee.ifa_next + let ifaName = String(utf8String: ptr!.pointee.ifa_name) + if ifaName == "pdp_ip0" {return true} + } + } + return false + } +} diff --git a/Kiwix/Kiwix-Bridging-Header.h b/Kiwix/Kiwix-Bridging-Header.h index edada6d9..7d950bff 100644 --- a/Kiwix/Kiwix-Bridging-Header.h +++ b/Kiwix/Kiwix-Bridging-Header.h @@ -5,3 +5,4 @@ #import "ZimReader.h" #import "ZimIndexer.h" +#include diff --git a/Kiwix/Operations/UIProcedure.swift b/Kiwix/Operations/UIProcedure.swift index c918149b..5f8ed1d5 100644 --- a/Kiwix/Operations/UIProcedure.swift +++ b/Kiwix/Operations/UIProcedure.swift @@ -133,7 +133,7 @@ extension AlertProcedure { if book.state == .cloud { alert.add(actionWithTitle: Localized.Library.download, style: .default) { _ in OperationQueue.main.addOperation({ - if true { + if UIDevice.hasCellularCapability { UIQueue.shared.add(operation: download(context: context, bookID: book.id)) } else { Network.shared.start(bookID: book.id, useWifiAndCellular: false)