SimonSimCity / Xamarin-CrossDownloadManager

A cross platform download manager for Xamarin
MIT License
149 stars 68 forks source link

Can't Get CrossDownloadManager to Work on iOS! #126

Closed jervaughan closed 4 years ago

jervaughan commented 4 years ago

I am having major issues getting CrossDownloadManager to initiate for a Xamarin iOS project. The Android version of the project works fine.

When debugging with the simulator I did have an error trying to access files on a HTTP site, so I added entries for NSAppTransportSecurity to my Info.plist. This fixed the issue and allowed threads to start, but nothing is being downloaded and the threads never seem to complete.

Does the Deployment Target need to be a specific version? I feel like I've checked everything else per the documentation & reading through previous issues.

image

AppDeletegate.cs

public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            Plugin.Segmented.Control.iOS.SegmentedControlRenderer.Initialize();
            Rg.Plugins.Popup.Popup.Init();

            //InitDownloadManager();

            //UINavigationBar.Appearance.TintColor = new UIColor(142, 191, 221, 100);
            //UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
            //{
            //    Font = UIFont.FromName("FontAwesome5Solid", 20)
            //});

            LoadApplication(new App());

            InitDownloadManager();

            return base.FinishedLaunching(app, options);
        }

        /**
         * Save the completion-handler we get when the app opens from the background.
         * This method informs iOS that the app has finished all internal processing and can sleep again.
         */
        public override void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, Action completionHandler)
        {
            CrossDownloadManager.BackgroundSessionCompletionHandler = completionHandler;
        }

        void InitDownloadManager()
        {
            CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string>(file => {
                string fileName = (new NSUrl(file.Url, false)).LastPathComponent;
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
            });
        }
    }

PCL code (works fine on Android, does execute on iOS but doesn't do anything... even tried a public HTTPS file as shown below)

private void DownloadDocument(object obj)
        {
            var document = obj as Document;

            if (document != null)
            {
                try
                {
                    var downloadManager = CrossDownloadManager.Current;
                    var file = downloadManager.CreateDownloadFile("https://www.fnordware.com/superpng/pnggrad16rgb.png");

                    downloadManager.Start(file, true);
                }
                catch (Exception ex)
                {

                }
            }
        }

Platform:

Device:

SimonSimCity commented 4 years ago

@JerVaughan Can you please try the sample application which is part of this repo and see if you have problems there as well?

jervaughan commented 4 years ago

Hi SimonSimCity,

Yes, the sample application appears to work fine with iOS. I added the following to AppDelegate.cs, and I can see the files in the ~/Library/Developer/CoreSimulator/.../Documents/ folder on my brand new Mac Mini when running the iOS Simulator (iPhone iOS 13.7).

If I'm specifying "Environment.SpecialFolder.MyDocuments" as the PathNameForDownloadedFile, then where should I expect to see the downloaded files when I use my iPad Mini (i.e. a physical device, not iOS Simulator)?

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string>(file => {
                string fileName = (new NSUrl(file.Url, false)).LastPathComponent;
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
            });

            return true;
        }
jervaughan commented 4 years ago

FYI... I can also see the downloaded file when running the iOS Simulator on my real app too, so it is working. The sample app helped me locate where to find the files on my Mac Mini that's connected to Visual Studio.

I think I'm just confused as to where to locate the files once the IPA is distributed/installed & files are downloaded on real devices.

jervaughan commented 4 years ago

Additional followup... I can also see the file on my iPad Mini if it's connected to iTunes on my PC after adding the following to Info.plist:

<key>UIFileSharingEnabled</key>
<true />

So I'm getting closer, but my goal is to be able to see the downloaded file in the "Files" app on my iPad... preferably in the "On My iPad" browsing section.

SimonSimCity commented 4 years ago

Ok, this is a different topic which you'd have to look up yourself - I haven't looked into this yet. As far as I know, the iOS internal download manager downloads the file into an app internal space, but how to move it from there to another place is something I don't known how to do.

Wish you all the best. Feel free to post the solution here once you found it.

Closing this issue because the request now is out of scope of this package.

jervaughan commented 4 years ago

Simon,

Please take a look at this link, particularly the section in the screenshot below. Since iOS 11, you can add the following to get the app’s documents to display in the “Files” app:

LSSupportsOpeningDocumentsInPlace
<true />"

https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system

[cid:image001.png@01D68C33.96E24400]

Thanks! Jeremy Vaughan Software Engineer 610.390.6860 | jeremyv@geninf.commailto:jeremyv@geninf.com [cid:image002.png@01D68C33.96E24400] ONE SMART WAY, BATON ROUGE, LA

From: Simon Schick notifications@github.com Sent: Wednesday, September 16, 2020 12:57 PM To: SimonSimCity/Xamarin-CrossDownloadManager Xamarin-CrossDownloadManager@noreply.github.com Cc: Jeremy P. Vaughan jeremyv@geninf.com; Mention mention@noreply.github.com Subject: Re: [SimonSimCity/Xamarin-CrossDownloadManager] Can't Get CrossDownloadManager to Work on iOS! (#126)

Closed #126https://github.com/SimonSimCity/Xamarin-CrossDownloadManager/issues/126.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/SimonSimCity/Xamarin-CrossDownloadManager/issues/126#event-3774186007, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AP7YPIML4X6GEUIMPXANVFLSGDU6LANCNFSM4RNRWBEQ.

lacielsa commented 3 years ago

Simon, Please take a look at this link, particularly the section in the screenshot below. Since iOS 11, you can add the following to get the app’s documents to display in the “Files” app: LSSupportsOpeningDocumentsInPlace " https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system [cid:image001.png@01D68C33.96E24400] Thanks! Jeremy Vaughan Software Engineer 610.390.6860 | jeremyv@geninf.commailto:jeremyv@geninf.com [cid:image002.png@01D68C33.96E24400] ONE SMART WAY, BATON ROUGE, LA From: Simon Schick notifications@github.com Sent: Wednesday, September 16, 2020 12:57 PM To: SimonSimCity/Xamarin-CrossDownloadManager Xamarin-CrossDownloadManager@noreply.github.com Cc: Jeremy P. Vaughan jeremyv@geninf.com; Mention mention@noreply.github.com Subject: Re: [SimonSimCity/Xamarin-CrossDownloadManager] Can't Get CrossDownloadManager to Work on iOS! (#126) Closed #126<#126>. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<#126 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AP7YPIML4X6GEUIMPXANVFLSGDU6LANCNFSM4RNRWBEQ.

Hi @JerVaughan . Could you tell me if you get CrossDownloadManager to Work on iOS?. If so, could you tell me how you did it?