Search code examples
swiftwkwebview

is it possible to open custom popup when click on copy link on instagram in swift


I develop an app in which I open Instagram in wkwebview and I want to open popup when a user taps on the copy link by tapping on three dots.


Solution

  • Add this code in view did load-:

    NotificationCenter.default.addObserver(self, selector: #selector(clipboardChanged),
                                               name: UIPasteboard.changedNotification, object: nil)
    

    And further, if you want to open popup in your clipboard in this event -:

    @objc func clipboardChanged(){
        let pasteboardString: String? = UIPasteboard.general.string
        if let theString = pasteboardString {
            print("String is \(theString)")
           
              // Open your view controller here 
            
        }
    }