react-native-share-menu icon indicating copy to clipboard operation
react-native-share-menu copied to clipboard

[iOS] Share fails on a certain type of apps, such as Zillow

Open robbiedood opened this issue 3 years ago • 2 comments

Dear react-native-share-menu friends,

Thanks for creating such a nice tool. We are testing the Test app in the example with a variety of apps.

We found that there is a kind of app, such as Zillow, attempting to create new instance of Test app inside itself. In such scenario, it would fail --- can not create a Test app, and would not direct any information to an existing Test app.

I was wondering if anyone gets the same problem. Hope to hear your expertise on potential solutions.

Best, --Luke

robbiedood avatar Jan 13 '22 02:01 robbiedood

Experiencing the same in TikTok

hyochan avatar Feb 24 '22 08:02 hyochan

I've encountered with a similar issue for Medium posts. After seeing this issue I've also tried for Zillow posts and do some digging. It turns out both Medium and Zillow (and probably some other apps) return an array of attachments which contains an image.

 func handlePost(_ item: NSExtensionItem, extraData: [String:Any]? = nil) {
    guard let provider = item.attachments?.first else {
      cancelRequest()
      return
    }
    if let data = extraData {
      storeExtraData(data)
    } else {
      removeExtraData()
    }

    if provider.isText {
      storeText(withProvider: provider)
    } else if provider.isURL {
      storeUrl(withProvider: provider)
    } else {
      storeFile(withProvider: provider)
    }
  }

in this code block provider is set to this "image" and then (for some reason, I'm not quite sure why) the storeFile method in the else block throws an error so nothing happens when you click on your app icon. In my use case image is not important I just want to get the url or the text so I've modified the code as

guard let provider = item.attachments?.first(where: { $0.isText || $0.isURL }) else {
       cancelRequest()
       return
     }

so that I get the text or the url from attachments array if there are any and cancel the request otherwise. It's not really a clean solution but I hope it helps with your use cases too. @lukelu520 @hyochan

Edit: I forgot to add the file location, so here it is /react-native-share-menu/ios/ShareViewController.swift

Dooqp avatar May 02 '24 12:05 Dooqp