iossafarisocialshare

How can i share a url like Safari do in my own app


I want to share a url like what Safari do in my own iOS app, How can i do this? Use socail framework can share in some specified social plartform, but in my case ,I just want to share url like Safari.


Solution

  • Do you think on UIActivityViewController?

    enter image description here

    @IBAction func shareTextButton(_ sender: UIButton) {
    
        // image to share
        let link = "https://www.google.rs/"
    
        // set up activity view controller
        let activityViewController = UIActivityViewController(activityItems: [link], applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
    
        // exclude some activity types from the list (optional)
        activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
    
        // present the view controller
        self.present(activityViewController, animated: true, completion: nil)
    
    
    }