예제 #1
0
        public NSUrl DocumentURLForName(string name)
        {
            var url = DocumentsDirectory.Append(name, false);

            url = url.AppendPathExtension(AppConfig.ListerFileExtension);
            return(url);
        }
예제 #2
0
        void CopyFileToDocumentsDirectory(NSUrl fromUrl)
        {
            NSUrl toURL = DocumentsDirectory.Append(fromUrl.LastPathComponent, false);

            bool              success = false;
            NSError           error;
            NSFileCoordinator fileCoordinator = new NSFileCoordinator();

            fileCoordinator.CoordinateWriteWrite(fromUrl, NSFileCoordinatorWritingOptions.ForMoving, toURL, NSFileCoordinatorWritingOptions.ForReplacing, out error, (src, dst) => {
                NSFileManager fileManager = new NSFileManager();
                success = fileManager.Copy(src, dst, out error);

                if (success)
                {
                    var attributes = new NSFileAttributes {
                        FileExtensionHidden = true
                    };
                    fileManager.SetAttributes(attributes, dst.Path);
                    Console.WriteLine("Moved file: {0} to: {1}.", src.AbsoluteString, dst.AbsoluteString);
                }
            });

            // In your app, handle this gracefully.
            if (!success)
            {
                Console.WriteLine("Couldn't move file: {0} to: {1}. Error: {3}.", fromUrl.AbsoluteString,
                                  toURL.AbsoluteString, error.Description);
            }
        }
예제 #3
0
        void MakeItemUbiquitousAtURL(NSUrl sourceURL)
        {
            string destinationFileName = sourceURL.LastPathComponent;
            NSUrl  destinationURL      = DocumentsDirectory.Append(destinationFileName, false);

            // Upload the file to iCloud on a background queue.
            ThreadPool.QueueUserWorkItem(_ => {
                NSFileManager fileManager = new NSFileManager();
                NSError error;
                bool success = fileManager.SetUbiquitous(true, sourceURL, destinationURL, out error);

                // If the move wasn't successful, try removing the item locally since the document may already exist in the cloud.
                if (!success)
                {
                    fileManager.Remove(sourceURL, out error);
                }
            });
        }