コード例 #1
0
        private void FindImageByUrl(NSString url)
        {
            var fn = tempDirectory.AppendPathComponent(url.LastPathComponent);

            if (File.Exists(fn))
            {
                File.Delete(fn);
            }
            // Replacing host to punycode to handle multi-byte domain
            var r           = new Regex(Regex.Escape(url.PathComponents[1]));
            var punycoded   = new IdnMapping().GetAscii(url.PathComponents[1]);
            var replacedUrl = r.Replace(url, punycoded, 1);

            try
            {
                using (var client = new WebClient())
                {
                    client.DownloadFile(replacedUrl, fn);
                }
            }
            catch
            {
                ShowAlertOnWindow("画像のダウンロードに失敗しました", "エラー", NSAlertStyle.Critical);
                return;
            }
            FindImage(fn);
        }
コード例 #2
0
        void OnFileSelect(string fileName)
        {
            var currentPath = new NSString(CurrentPath);
            var newPath     = currentPath.AppendPathComponent(new NSString(fileName)).ToString();

            NavigationController.PushViewController(new FileViewController(newPath), true);
        }
コード例 #3
0
        void OnFolderSelect(string directoryName)
        {
            var currentPath = new NSString(CurrentPath);
            var newPath     = currentPath.AppendPathComponent(new NSString(directoryName));

            NavigationController.PushViewController(new PathViewController(
                                                        newPath.ToString()), true);
        }
コード例 #4
0
        public void ReadFile()
        {
            try
            {
                // Gets the direct path to the file
                NSString folderPath = dataPath.AppendPathComponent(new NSString("testfile.txt"));

                // Handle the data and read it from the specific path
                NSFileHandle nsfh = NSFileHandle.OpenRead(folderPath);

                // Gets the data from the file
                NSData data = nsfh.ReadDataToEndOfFile();

                string text = data.ToString();
            }
            catch (Exception ex)
            {
                // Failed read data from a file
            }
        }
コード例 #5
0
        public void CreateFolder()
        {
            try
            {
                NSString foldername = new NSString("MyFolder");

                documentsDirectory = new NSString(path[0]);
                dataPath           = documentsDirectory.AppendPathComponent(foldername);


                NSFileManager.DefaultManager.CreateDirectory(dataPath, false, null);
            }catch (Exception ex)
            {
            }
        }
コード例 #6
0
        void SendToInstagram(UIImage image)
        {
            NSUrl instagramURL = new NSUrl("instagram://");

            if (UIApplication.SharedApplication.CanOpenUrl(instagramURL))
            {
                UIImage  imageToUse        = PhotoService.Rotate(image, image.Orientation);
                NSString documentDirectory = (new NSString(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
                string   saveImagePath     = documentDirectory.AppendPathComponent(new NSString(@"Image.ig"));
                NSData   imageData         = PhotoService.ResizeImage(imageToUse).AsPNG();
                imageData.Save(saveImagePath, true);
                NSUrl imageURL = NSUrl.FromFilename(saveImagePath);

                DocumentController            = new UIDocumentInteractionController();
                DocumentController.Url        = imageURL;
                DocumentController.Delegate   = new DocumentInteractionControllerDelegate(this);
                DocumentController.Uti        = "com.instagram.photo";
                DocumentController.Annotation = new NSMutableDictionary <NSString, NSString> {
                    { new NSString("InstagramCaption"), new NSString(Challenge.InstaCaption ?? "") }
                };
                DocumentController.PresentOpenInMenu(new RectangleF(1, 1, 1, 1), View, true);
            }
        }