您需要保存在UserDefaults用戶選擇
下面的代碼是用斯威夫特3
如果你不希望加載entryViewController然後在AppDelegate中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//retrieve values from UserDefaults
//for the first time it will be false, because it was not set earlier
let isAccepted = UserDefaults.standard.bool(forKey: "isAccepted")
if isAccepted == false {
//present your disclaimer here
}else{
//show entryViewController
}
return true
}
也可以加載entryViewController和現在的免責聲明瞬間,然後在您的entryViewController:
override func viewDidLoad() {
super.viewDidLoad()
//retrieve values from UserDefaults
//for the first time it will be false, because it was not set earlier
let isAccepted = UserDefaults.standard.bool(forKey: "isAccepted")
if isAccepted == false {
//present your disclaimer here
}
}
在DisclaimerVC:
@IBAction func accept(_ sender: UIButton){
//it can be another action in your controller
//but anyway, you should save user choice after that
UserDefaults.standard.set(true, forKey: "isAccepted")
//add code here to dismiss disclaimer
}
這已經被問過很多次。請在提問前進行搜索。這裏是一個示例解決方案:https://github.com/mattneub/RegistrationExample – matt
你介意解釋爲什麼這被標記爲重複?您的答案和iOS項目都不支持免責聲明。 –
獅子狗和西班牙狗都是狗。你需要製造一隻狗;這只是一個偶然的事實,它是什麼品種。正如我所說過的,一次性顯示視圖控制器(或直到用戶滿足某些要求)的問題在這裏已經得到了很大的處理。 – matt