Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Does NSFilePromiseReceiver work?

$
0
0

I can't find an example of drag/drop with NSFilePromiseReceiver instead of just handling views or file URLs. I've built something based loosely around Apple's documentation and the wiring seems to be more or less correct. I can see the debugger getting to promise.ReceivePromisedFiles, but, I never get to urlList.Add. I've tried making the operation queue class-level so it doesn't get cleaned up before it can process things. And even tried saving off the promise itself for the same reason. But that's ugly and clunky and still doesn't work anyway.

Note: This is an attempt to handle files dropped from Apple's Photos.app - dropping files from finder was working with the old file URL method. And I know that async execution may mean that urlList isn't populated when I hand it off to be handled. But I'm not getting as far as getting the actual file promise working, so one thing at a time.

        [Export("performDragOperation")]
        public override bool PerformDragOperation(NSDraggingInfo sender)
        {
            var urlList = new List<string>();
            var types = NSArray.FromIntPtrs(new IntPtr[] { new ObjCRuntime.Class(typeof(NSFilePromiseReceiver)).Handle, new ObjCRuntime.Class(typeof(NSUrl)).Handle });

            sender.EnumerateDraggingItems(NSDraggingItemEnumerationOptions.ClearNonenumeratedImages, this, types, new NSDictionary(), (NSDraggingItem draggingItem, nint idx, ref bool stop) =>
            {
                Console.WriteLine("DraggingItem: {0}", draggingItem);
                if (draggingItem.Item is NSFilePromiseReceiver promise)
                {
                    promise.ReceivePromisedFiles(new NSUrl(Path.GetTempFilePath()), new NSDictionary(), _dragOperations,
                        (NSUrl url, NSError error) => {
                            urlList.Add(url.Path);
                        });

                }
                else if (draggingItem.Item is NSUrl url)
                {
                    urlList.Add(url.Path);
                }
            });


        HandleUrls(urlList);

            return true;
        }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>