本文介绍了按下菜单按钮后如何在后台放置Apple TV应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试过使用私有方法,在按下菜单按钮后将应用程序置于后台;并且以下代码正常工作:
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 ViewController {
UITapGestureRecognizer *tapRecognizer;
}
-(void)viewDidLoad {
[super viewDidLoad];
tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeMenu]];
[self.view addGestureRecognizer:tapRecognizer];
}
-(void)handleTap:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Menu button released");
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
}
}
但是我希望在不使用私有方法"suspend"的情况下获得相同的结果,因为Apple可能会因为使用私有方法而拒绝该应用程序.
But I would like to get the same result without using the private method "suspend" because Apple could reject the app due to using a private method.
[app performSelector:@selector(suspend)];
任何建议将不胜感激
推荐答案
Swift 3解决方案:
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))
}
}
这篇关于按下菜单按钮后如何在后台放置Apple TV应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!