Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active April 8, 2025 18:04
Show Gist options
  • Save brennanMKE/9f406e41a95aed6e22e13bf7ec05e00d to your computer and use it in GitHub Desktop.
Save brennanMKE/9f406e41a95aed6e22e13bf7ec05e00d to your computer and use it in GitHub Desktop.
Check if iOS app supports background downloads
var supportsBackgroundDownloads: Bool {
guard let appDelegate = UIApplication.shared.delegate else {
return false
}
let signature = "application:handleEventsForBackgroundURLSession:completionHandler:"
var methodCount: UInt32 = 0
guard let methodList = class_copyMethodList(type(of: appDelegate), &methodCount) else {
return false
}
let range = 0..<Int(methodCount)
let found = range.reduce(into: []) { result, index in
let selName = sel_getName(method_getName(methodList[index]))
let methodName = String(cString: selName, encoding: .utf8)!
result.append(methodName)
}.first(where: { $0 == signature }) != nil
return found
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment