Dav*_*say 15 iphone swift ios8
我正在尝试使用Swift以编程方式返回iOS8应用程序中的主屏幕.我想继续在后台运行应用程序.关于如何做到这一点的任何想法?
在此先感谢您的帮助.
小智 31
启动应用程序时,系统调用UIApplicationMain函数; 在其他任务中,此函数创建一个单独的UIApplication对象.此后,您可以通过调用sharedApplication类方法来访问该对象.
要正常退出(iOS开发人员库明确警告您不要使用exit(0),因为这会记录为崩溃),您可以使用:
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
例如,当用户摇动设备时,我的应用会退出.所以,在ViewController.swift中:
override func motionEnded(motion: UIEventSubtype,
    withEvent event: UIEvent?) {
        if motion == .MotionShake{
            //Comment: to terminate app, do not use exit(0) bc that is logged as a crash.
            UIControl().sendAction(Selector("suspend"), to: UIApplication.sharedApplication(), forEvent: nil)
        }}
avi*_*ran 22
斯威夫特4:
UIControl().sendAction(#selector(NSXPCConnection.suspend),
                       to: UIApplication.shared, for: nil)
| 归档时间: | 
 | 
| 查看次数: | 24730 次 | 
| 最近记录: |