免责声明:这样做几乎肯定会导致您的应用从应用商店中被拒绝,因此您应该确保它只显示在测试版和内部版本上。如果您需要Apple接受它,我建议通过React Native实现UIActionSheets和UIAlerts;有很多好的库可以模拟模态。
你需要在本机方面这样做。您可以将以下代码添加到AppDelegate:
var debugWindow: UIWindow?
@objc func pressButton(_ sender: UIButton) {
print("Do debugging here")
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let screenSize = UIScreen.main.bounds
let buttonController = UIViewController()
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
button.setTitle("+", for: .normal)
button.backgroundColor = UIColor.blue
button.addTarget(self, action: #selector(pressButton(_:)), for: .touchUpInside)
button.layer.cornerRadius = 25
button.layer.masksToBounds = true
buttonController.view = button
debugWindow = UIWindow.init(frame: CGRect(x: screenSize.width - 100, y: screenSize.height - 100, width: 50, height: 50))
debugWindow!.rootViewController = buttonController
debugWindow!.windowLevel = UIWindow.Level.alert + 1000;
debugWindow!.makeKeyAndVisible()
return true
}