我想訪問iOS專用功能_setApplicationIsOpaque:
(僅供個人使用和測試)。無法識別的選擇器調用「_setApplicationIsOpaque:」
我已經實現了這個代碼:
@_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)
}
}
我發現這種方式來訪問私有的iOS API在下面的StackOverflow問題Access Private UIKit Function Without Using Bridging Header 和this file在GitHub上。
的問題是,在運行應用程序,我得到的錯誤
[UIApplication _setBackgroundStyle:]: unrecognized selector sent to class 0x10437f348
我發現的UIApplication in this GitHub repository iOS的私有的API的報頭。
很抱歉,如果我做了一些錯誤的語言,我是意大利人。 – ale00
SPOLIER:我不能讓應用程序背景透明 – ale00