2

Update: don't have time yet to test provided answer, but will keep this answer updated as I try different things.

In the iOS 14 Simulator, when I open the share sheet and click their Share Target, the Apple News app is launched immediately and they check if the shared URL has been added to their index.

My question is how are they launching their app immediately without any user interaction?

A gif is worth about 100,000 words: https://giphy.com/gifs/HPzTNyWGDDMVwASQ9z

I would imagine it may be some combination of registering a Universal Link and then programmatically triggering that from the Share Extension View Controller, but I’m wondering if anyone has any better ideas.


A couple of other places I've asked:

Swift Subreddit

iOS Programming Subreddit

technoplato
  • 3,293
  • 21
  • 33

1 Answers1

1

This is just an open URL call to a news app. Prior to iOS 14, it was named as copy to app name. To achieve this you need to specify the supported document type for your application in plist using key CFBundleDocumentTypes. Refer to apple documentation for more info: https://help.apple.com/xcode/mac/current/#/devddd273fdd

There is a change in share sheet option listings.

case 1: When your application doesn't support any kind of extension. And have supported document add to plist. Your application will appear in the share sheet for supporting documents. On tap, your application gets an OpenURL call with the URL of the document shared.

case 2: Your application supports share extension or action extension, then your open URL call option for your application will not appear in the share sheet. if the share extension and action extension activation predicate are not satisfied and the document shared is supported by your application that option will appear the same as case 1. (Summary: if share extension or action extension is listed in share sheet then open URL option will not be listed.)

Note: Limitation of openURL call is, it supports only a single URL. For example, you are sharing multiple files, your application OpenURL option will appear. But on tap, your application will receive only one URL.

If your requirement is sharing only a single URL and your application doesn't have a share extension and action extension. Then key CFBundleDocumentTypes is your friend.

Manish Punia
  • 747
  • 4
  • 9
  • Thank you very much for your answer. I am working on my backend at the moment, but once I finish and return to frontend work, I'm going to try this out. Will certainly provide the upvote and check if this works. One question though: what is the Document Type I need to opt in to to accept ___ALL URLS___? – technoplato Dec 14 '20 at 12:10
  • 1
    Value for key `LSItemContentTypes` is an array type that accepts an array of strings (UTI for documents). For supporting all the URLs you can use `public.url`. – Manish Punia Dec 15 '20 at 04:29
  • Cheers @manish punia. I'm still working on my backend, but as soon as I get to the next flip flop point I'll try your solution. Thank you very much! – technoplato Dec 15 '20 at 12:44
  • @lustig is it working? I have tried this solution but nothing changed. – Picode Dec 29 '20 at 07:16
  • @picode Have not been able to try this yet as I'm still working backend. Check in the subreddits linked in the question. They have posted more options. What exactly did you try? – technoplato Dec 29 '20 at 13:16
  • @lustig I will try, thanks. I was tried to "CFBundleDocumentTypes" at solution. – Picode Dec 30 '20 at 13:33