あなたはAppDelegateでそれをしようとした場合、あなたがwindow?.rootViewController?
0に警告を提示しなければなりません
var alertController = UIAlertController(title: "Title", message: "Any message", preferredStyle: .ActionSheet)
var okAction = UIAlertAction(title: "Yes", style:
UIAlertActionStyle.Default) {
UIAlertAction in
NSLog("OK Pressed")
}
var cancelAction = UIAlertAction(title: "No", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.window?.rootViewController?.presentViewController(alertController, animated: true, completion: nil)
let launchedBefore = UserDefaults.standard.bool(forKey: "launcedBefore")
に入る値(真または偽)を確認してください。警告を表示するかどうかは、bool
の値によって異なります。
「AppDelegate –
のdidFinishLaunchingWithOptions」機能で警告を表示しますが、コードに「何の問題がありますか? – Larme
"launcedBefore"!= "launchBefore" –