1

I have created one single application to explain my question well. There is a button in the page(ViewController)

Here is the ViewController.swift file

import UIKit
import SwiftKeychainWrapper

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let resultOfTheMethod = checkKeychainWrapperExistOrNot()
        print("checkKeychainWrapperExistOrNot method result: \(resultOfTheMethod)")
    }

    @IBAction func btnPressed(_ sender: UIButton) {
        saveSomeDummyDataInToTheKeychainWrapper()
    }

    func saveSomeDummyDataInToTheKeychainWrapper()
    {
        KeychainWrapper.standard.set("TEST_123", forKey: "someKey4KeychainWrapper")
    }

    func checkKeychainWrapperExistOrNot () -> Bool {
        if let _ = KeychainWrapper.standard.string(forKey: "someKey4KeychainWrapper")
        {
            return true
        }
        return false
    }
}

Let me explain what i did in order: I have plugged my iPhone in to my mac. And then I run the app as a first time with using my iPhone. I got this output from viewDidLoad method:

checkKeychainWrapperExistOrNot method result: false

And then I have clicked the button. After that I have closed the application and opened it again. I got this output:

checkKeychainWrapperExistOrNot method result: true

And then i have done with these steps in order: Removed the app from my iPhone, Clicked: Product > "Clean Build Folder", And then re run the application. I got this output:

checkKeychainWrapperExistOrNot method result: true

Result is: KeyChainWrapper item is not deleted. I would like to confirm it because it is weird little bit: I am done with this application: I have removed it from my phone. But some files still exist in my iPhone related with this removed app.

So my first question is: Aren't KeyChainWrapper items deleted when we remove the application from iPhone? When are these deleted?

Second question: How can I remove all KeychainWrapper items? Let's assume I have lots of KeychainWrapper items like this:

KeychainWrapper.standard.set("TEST_123", forKey: "someKey4KeychainWrapper")
KeychainWrapper.standard.set("TEST_123", forKey: "someKey4KeychainWrapper2")
KeychainWrapper.standard.set("TEST_123", forKey: "someKey4KeychainWrapper3")

How can I remove all of them?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
mannyCalavera
  • 593
  • 1
  • 4
  • 23
  • Related: https://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled – vadian Mar 20 '19 at 11:34
  • 1
    Why do you even need a framework or whatever that is created by somebody else just in order to save and delete data in the key chain? – El Tomato Mar 20 '19 at 11:42
  • @vadian Totally Related? Let me compare the link you have posted. He asked this: I want to delete KeychainWrapper items after user remove the app from device. What did I asked? I want to confirm this: "Does the KeyChainWrapper item remain on the device after we uninstall the app from the iPhone?" For example UserDefaults are deleted from the phone after user removes the app from the phone. This is not totally related.. – mannyCalavera Mar 20 '19 at 12:00
  • @vadian and what about second question? I have asked another thing. I know i can use UserDefaults as an alternative(like in the reply in your link) But i am asking: How can I remove all KeychainWrapper items? Please don't write "related" quick to our questions before you read all of them. Please.. – mannyCalavera Mar 20 '19 at 12:02
  • @ElTomato I am using keychainWrapper for touchid&faceid issue. I noticed that Keychainwraper items remains in the key chain in iPhone even I remove the app from Iphone. And then I wanted to "confirm" this. And then I have created this simple application to explain my questions well in here stackoverflow. – mannyCalavera Mar 20 '19 at 12:15
  • 1
    If the answer was *totally related* I would have marked it as duplicate. – vadian Mar 20 '19 at 12:17
  • But minus button is clicked with "related" comment "in a same time". Was it necessary? No. It is clicked because my question was not read completely. And then the "Undo" button was clicked after my two comments. I made a research about it. And then I wanted to confirm it. All these things took my time. It is worth! And this is an effort. These does not deserve a minus. Now my second question is still pending because of these. – mannyCalavera Mar 21 '19 at 10:57

0 Answers0