3 Replies
      Latest reply on Nov 8, 2019 12:44 AM by eskimo
      RezuanB Level 1 Level 1 (0 points)

        I created a browser based on WKWebView. I need to add the ability to download videos, photos, music, etc. in the AppStore there are many applications, such as DManager, where you open any link, and if it contains a video ( youtube, rutube...), music (zaycev.net), it immediately determines that the site contains a media file and offers to download. Searched all Google, but even the approximate decision did not find.

        • Re: How to create browser downloader
          eskimo Apple Staff Apple Staff (12,325 points)

          The general strategy for implementing a web download feature:

          1. Set yourself as the web view’s navigation delegate navigationDelegate.

          2. Implement one or more of the WKNavigationDelegate methods.  Typically this is either:

            depending on whether you need to see the server’s response or not.

          3. After deciding that the navigation should be treated as a download, complete the policy request with .cancel.  This prevents the web view from doing anything more with the navigation, allowing you to take over.

          4. Then use URLSession to download the resource.

          It’s easy to get this working in simple cases.  In complex cases it’s quite tricky.  For example:

          • Many downloads are authenticated, so you need to find a way to get the authentication state out of the web view and into your URLSession.

          • Some content is not represented by a single resource.  The most common example of this is video, where a lot of video uses multiple resources (typically using HTTP Live Streaming).

          • On iOS you typically want to run the download in a background session, and that introduces its own complexities.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: How to create browser downloader
              RezuanB Level 1 Level 1 (0 points)

              Could you help with this question in more detail?

                • Re: How to create browser downloader
                  eskimo Apple Staff Apple Staff (12,325 points)

                  Could you help with this question in more detail?

                  I’m sorry but I don’t see a lot of detail in that other post; it seems to be largely a restatement of your requirements.

                  Earlier in this thread I’ve given you some technical pointers on how to proceed.  My recommendation is that you try these out and see how far you get.  If you run into snags, post your questions here and I’ll have a go at answering them.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"