2

I have hint view (tooltip). And I want it display in my app 1 time per download app. When user downloading app this tooltip is showing and then dismiss. When user delete app and again downloading tooltip should work again.

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)

and I have key

public var hintView: Bool {
        get {
            return setting.bool(forKey: Key.hintView)
        }
        set {
            setting.set(false, forKey: Key.hintView)
        }
    }

How can I control when user deletes app and again download it

  • You could store a bool value like `firstRunFinished` and set to true once the app launched. Or If you want the user to see ToolTip at least once, then you have to set specific bool for that. – Lal Krishna Jan 28 '20 at 05:14
  • As an FYI, I would recommend https://github.com/jrendel/SwiftKeychainWrapper or something from https://github.com/jrendel/SwiftKeychainWrapper. These are generally more reliable and have increased security. Answers below are more than sufficient though. – Harry J Jan 28 '20 at 05:36
  • @Аба-Бакри Ибрагимов please check my answer and let me know it is working or not. – HardikS Jan 28 '20 at 09:22
  • guys I have a question, I have two hint views in two different screens, and I can't use same key for both screens, but when I create two keys , one affects the other and changes his bool type, How I can avoid it – Аба-Бакри Ибрагимов Jan 29 '20 at 11:46

3 Answers3

2

Store a bool in UserDefaults. Once the user uninstalls the app, the data will be deleted.

in your AppDelegate.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.

then inside your didFinishLaunchingWithOptions function

 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")
Keshu R.
  • 5,045
  • 1
  • 18
  • 38
1

Change your getter and setter for hintView like below

public var hintView: Bool {
    get {
        return setting.bool(forKey: Key.hintView)
    }
    set {
        setting.set(true, forKey: Key.hintView)
        setting.synchronize()
    }
}

And now use your hintView variable like below for showing and hiding the toolbar.

//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")
}

I hope it will more clear to you

HardikS
  • 656
  • 3
  • 10
0
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)
       }
}