ShareLink copying the wrong URL into Messages

Hi,

I am working on a habit tracking application. The main feature is to allow users to share habits. I am using a ShareLink view to allow users to send the link (using firebase to produce dynamic links).

When users press "copy" the correct link is copied to their clipboard. When a user sends the link through messages via the ShareSheet, an incorrect link is produced.

Here is the view code that grabs the URL produced for each shared habit.

       ToolbarItem {
        if let url = sharedHabitViewModel.shareLink(for: habitId) {
          let _ = print("shared habit link unpacked: \(url)")
          ShareLink(item: url, message: Text("Hey, lets hold each other accountable by completing this shared habit!")) {
            Label(title: { Text("Share Habitat").foregroundColor(.primary)}, icon: {
              Image(systemName: "square.and.arrow.up")
            })
          }
        } else {
          EmptyView()
        }
      }

This is an example of the correct link:

https://habitatdebug.page.link/jUfhKiFH7EhxB7B

Here is an example of the incorrect link:

https://habitatdebug.page.link/s?socialDescription=User+has+invited+you+to+join+habit+Exercise&socialImageUrl=https://firebasestorage.googleapis.com:443/o/appIcon%252F.png?alt%3Dmedia%26token%3D4ca8-6db1-4faa-9de8-88beb74f0db2&socialTitle=Share

I do not understand how or why the incorrect link is being produced only with the messages application.

I also receive a long list of errors when I open the ShareLink, see additional text below.

Does this happen only with Message.app? If so, I'd suggest to change tag to Messages (https://developer.apple.com/forums/tags/messages/).

But even if not, I highly doubt that SwiftUI adds Firebase-related information to the link.

Hi, I have the same problem! My solution is to use two ShareLinks, one for AirDrop and one for iMessage. ShareLink change the link when NOT using SharePreview to a WRONG one, when using iMessage. See my workaround solution here:

ShareLink(item: settings.inviteURL) {
                        Label("AirDrop", systemImage: "square.and.arrow.up")
                    }
                    ShareLink(
                        item: settings.inviteURL,
                        subject: Text(subject),
                        message: Text(""),
                        preview: SharePreview(
                            settings.appName,
                                image: Image("AppIcon"))
                        ) {
                        Label("iMessage", systemImage: "square.and.arrow.up")
                    }

PS. You can read this support link to get more info: https://github.com/invertase/react-native-firebase/issues/3182

ShareLink copying the wrong URL into Messages
 
 
Q