How can I put an Apple TV app in background after pressing the Menu button

后端 未结 1 599
谎友^
谎友^ 2021-01-23 05:06

I have tried to use a private method to put the app in background after pressing the Menu button; and the following code works properly:

 @implementation ViewCon         


        
相关标签:
1条回答
  • 2021-01-23 05:50

    Swift 3 solution:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(gesture:)))
        tapRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.menu.rawValue)]
        self.view.addGestureRecognizer(tapRecognizer)
    }
    
    func handleTap(gesture: UITapGestureRecognizer){
        if gesture.state == UIGestureRecognizerState.ended {
            let app = UIApplication.shared
            app.perform(#selector(URLSessionTask.suspend))
        }
    }
    
    0 讨论(0)
提交回复
热议问题