I am trying to access the iOS private function _setApplicationIsOpaque:
(just for personal use and test).
I have implemented this code:
@_silgen_name("_setApplicationIsOpaque:") func _setApplicationIsOpaque(_ arg1: Bool)
let invokeSetApplicationIsOpaque: (Bool) -> Void = {
// The Objective-C selector for the method.
let selector: Selector = Selector(("_setApplicationIsOpaque:"))
guard case let method = class_getInstanceMethod(UIApplication.self, selector), method != nil else {
fatalError("Failed to look up \(selector)")
}
// Recreation of the method's implementation function.
typealias Prototype = @convention(c) (AnyClass, Selector, Bool) -> Void
let opaqueIMP = method_getImplementation(method)
let function = unsafeBitCast(opaqueIMP, to: Prototype.self)
// Capture the implemenation data in a closure that can be invoked at any time.
return{ arg1 in function(UIApplication.self, selector, arg1)}
}()
extension UIApplication {
func setApplicationIsOpaque(_ isOpaque: Bool) {
return invokeSetApplicationIsOpaque(isOpaque)
}
}
I found this way to access private iOS API in the following StackOverflow question Access Private UIKit Function Without Using Bridging Header and in this file on GitHub.
The problem is that running the app I get the error
[UIApplication _setBackgroundStyle:]: unrecognized selector sent to class 0x10437f348
I have found the header of iOS private APIs of UIApplication in this GitHub repository.