Cellular capability detection

This commit is contained in:
Chris Li 2017-02-24 14:19:32 -05:00
parent d43c964e3d
commit 14bbbd29bf
3 changed files with 18 additions and 1 deletions

View File

@ -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<ifaddrs>? = 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
}
}

View File

@ -5,3 +5,4 @@
#import "ZimReader.h"
#import "ZimIndexer.h"
#include <ifaddrs.h>

View File

@ -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)