我有提示视图(工具提示(。我希望它在我的应用程序中显示每个下载应用程序 1 次。当用户下载应用程序时,将显示此工具提示,然后关闭。当用户删除应用程序并再次下载工具提示时,应该会再次工作。
let options: AMTooltipViewOptions = .init(textColor: Color.guideSubTitle,
textBoxBackgroundColor: Color.guideScreenBackground,
textBoxCornerRadius: 8,
lineColor: Color.guideScreenBackground,
lineHeight: 15,
dotSize: 0,
focusViewRadius: 15,
focustViewVerticalPadding: 0,
focustViewHorizontalPadding: 0)
AMTooltipView(options: options,
message: Localizable.scan_open_from_gallery + "n" + Localizable.scan_clear,
focusView: content.openGalleryBtn, target: self)
我有钥匙
public var hintView: Bool {
get {
return setting.bool(forKey: Key.hintView)
}
set {
setting.set(false, forKey: Key.hintView)
}
}
如何控制用户何时删除应用程序并再次下载它
在UserDefaults
中存储一个布尔值。用户卸载应用后,数据将被删除。
在您的应用程序委托中.swift
let DEFAULTS = UserDefaults.standard
var isUserFirstTime = !DEFAULTS.bool(forKey: "isUserFirstLogin") // by default it will store false, so when the user opens the app for first time, isUserFirstTime = true.
然后在您的didFinishLaunchingWithOptions
函数中
if isUserFirstTime {
// your code here to show toolbar
} else {
// dont show toolbar
}
// once you have completed the operation, set the key to true.
DEFAULTS.set(true, forKey: "isUserFirstLogin")
更改您的 getter 和 setter forhintView
public var hintView: Bool {
get {
return setting.bool(forKey: Key.hintView)
}
set {
setting.set(true, forKey: Key.hintView)
setting.synchronize()
}
}
现在使用如下所示的hintView
变量来显示和隐藏工具栏。
//it will always returns false for first time when you install new app.
if hintView {
print("Hide Toolbar")
}
else {
//set flag to true for first time install application.
hintView = true
print("Show Toolbar")
}
希望你能更清楚
import Foundation
import AMTooltip
class HintViewController {
let userDefaults: UserDefaults = .standard
let wasLaunchedBefore: Bool
var isFirstLaunch: Bool {
return !wasLaunchedBefore
}
init() {
let key = "wasLaunchBefore"
let wasLaunchedBefore = userDefaults.bool(forKey: key)
self.wasLaunchedBefore = wasLaunchedBefore
if !wasLaunchedBefore {
userDefaults.set(true, forKey: key)
}
}
func showHintView(message: String!, focusView: UIView, target: UIViewController) {
let options: AMTooltipViewOptions = .init(textColor: Color.guideSubTitle,
textBoxBackgroundColor: Color.guideScreenBackground,
textBoxCornerRadius: 8,
lineColor: Color.guideScreenBackground,
lineHeight: 15,
dotSize: 0,
focusViewRadius: 15,
focustViewVerticalPadding: 0,
focustViewHorizontalPadding: 0)
AMTooltipView(options: options, message: message, focusView: focusView, target: target)
}
}