Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI 4.0 how to know if ShareLink has been shared successfully

Tags:

swift

swiftui

I am now working with the new SwiftUI 4.0 and using the new ShareLink feature . How can I know if a link or text has been shared successfully, any suggestions would be great ? I have a simple ShareLink like this

          ShareLink(item: InviteMessage) {
                    Text("Test Share")
                        .foregroundColor(.black)
                 }

before in SwiftUI 3.0 I would use this code

                .background(SharingViewController(isPresenting: $InviteOthers) {
                    let message = "Share Me"
                    let av = UIActivityViewController(activityItems: [message], applicationActivities: nil)
                    av.completionWithItemsHandler = { (activity, success, items, error) in

                        if success {
                            // shared successfully update count
                        }
                       }
                       
                    return av
                })
like image 496
user1591668 Avatar asked Nov 28 '25 08:11

user1591668


1 Answers

It doesn't seem possible to know if the content has been shared successfully, but you can at least detect if the link has been clicked with the simultaneousGesture modifier (onTapGesture doesn't work on ShareLink):

ShareLink(){}
.simultaneousGesture(TapGesture().onEnded() {
    print("clicked") 
})
like image 190
Jérôme Boé Avatar answered Dec 02 '25 05:12

Jérôme Boé



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!