공부/IOS swift
앱 강제종료 app Force quit
isntyet
2018. 8. 26. 18:24
특정 조건일떄 ios 앱을 강제 종료하여야 되어 방법을 찾고있었는데 너무 쉬웠다...
exit(0)
이렇게 하면 앱이 강제로 종료된다..
나는 이런식으로 사용하였다.
check후 알럿 확인을 누른 후 5초뒤 강제종료
if(!check){
let viewController = self.window!.rootViewController as? MainViewController
let alert = UIAlertController(title: "warning", message: "detected", preferredStyle: UIAlertControllerStyle.alert)
let done = UIAlertAction(title: "확인", style: UIAlertActionStyle.destructive, handler: { result in
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5), execute: {
exit(0)
})
})
alert.addAction(done)
viewController?.present(alert, animated: true, completion: nil)
}