void WriteImageToPath(UIImage image, string path) { NSFileManager.DefaultManager().RemoveItemAtPathError(path, null); NSData data = path.PathExtension().LowercaseString().IsEqualToString("png") ? UIImagePNGRepresentation(image) : UIImageJPEGRepresentation(image, 1.0); data.WriteToFileAtomically(path, true); }
/// <summary> /// Alls the inbox files. /// </summary> /// <returns></returns> public List <UPInboxFile> AllInboxFiles() { List <UPInboxFile> files = new List <UPInboxFile>(); #if PORTING Exception error; List <string> pathNames = NSFileManager.DefaultManager().ContentsOfDirectoryAtPathError(this.InboxPath, error); if (error) { if (error.Code() == NSFileReadNoSuchFileError) { DDLogInfo("Inbox directory %@ does not exist.", this.InboxPath); } else { DDLogError("Could not load files from inbox: %@", error); } } foreach (string path in pathNames) { UPInboxFile file = new UPInboxFile(this.InboxPath.StringByAppendingPathComponent(path), NSURL.FileURLWithPathIsDirectory(this.InboxPath.StringByAppendingPathComponent(path), false)); files.Add(file); } #endif return(files); }
private static void _Init(object sender = null, EventArgs e = null) { string oldID = iCloudID; object token = null; if (NSFileManager.InstancesRespondToSelector("ubiquityIdentityToken")) { token = NSFileManager.DefaultManager().UbiquityIdentityToken(); } if (token == null) { iCloudID = null; _userDefaults.RemoveObject(ID_KEY); } else { NSData data = NSKeyedArchiver.ArchivedData(token); iCloudID = Convert.ToBase64String(data.ToByteArray()); _userDefaults.SetObject(iCloudID, ID_KEY); } Synchronize(); if (iCloudID != oldID) { if (_accountChangedHandlers != null) { _accountChangedHandlers(null, EventArgs.Empty); } } }
/// <summary> /// Moves from URL. /// </summary> /// <param name="url">The URL.</param> /// <returns></returns> public Uri MoveFromUrl(Uri url) { return(null); #if PORTING string oldPath = url.Path; string newName = oldPath.LastPathComponent.StringByDeletingPathExtension(); string pathExtension = oldPath.LastPathComponent.PathExtension; string newPath = this.InboxPath.StringByAppendingPathComponent(oldPath.LastPathComponent); Exception error = null; if (!NSFileManager.DefaultManager().FileExistsAtPath(newPath)) { NSFileManager.DefaultManager().MoveItemAtPathToPathError(oldPath, newPath, error); } else { bool moved = false; for (int i = 1; (!moved && i < 100); i++) { string newName1 = $"{newName}-{i}.{pathExtension}"; newPath = this.InboxPath.StringByAppendingPathComponent(newName1); if (!NSFileManager.DefaultManager().FileExistsAtPath(newPath)) { moved = NSFileManager.DefaultManager().MoveItemAtPathToPathError(oldPath, newPath, error); } } } return(NSURL.FileURLWithPath(newPath)); #endif }
private void Run() { Debug.Log("Example 7 - Account Status"); // This is the Core Foundation way of checking if the user has changed // This method is NOT recommended by apple. But is the only option if you // are not using CloudKit (and are just using key value storage) Token = NSFileManager.DefaultManager().UbiquityIdentityToken; Unsubscriber = ICloudNotifications.AddIdentityDidChangeObserver(OnCloudIdentityChanged); // If your using cloud kit...apple has this to say: // CloudKit clients should not use this token as a way to identify // whether the iCloud account is logged in. Instead, use // accountStatusWithCompletionHandler: or // fetchUserRecordIDWithCompletionHandler: // https://developer.apple.com/documentation/foundation/nsfilemanager/1408036-ubiquityidentitytoken?language=objc // This is the cloudkit way // Listen for the accountStatusChanged notification // Apple says... "Notification posted when the status of the signed-in iCloud account may have changed." // This notification will fire for a number of reasons, not all of them will be related to signing in or // out of iCloud. For instance, toggling the iCloud Drive permission in iCloud settings will cause this // to fire CKContainer.AddAccountChangedNotificationObserver(AccountStatusChanged); // At this point you should sign in or out of iCloud to update the account stauts. Debug.Log("Account status notification handlers attached. Sign in or out of iCloud ot update."); Debug.Log("Waiting for change in account status..."); }
private static UPMInboxFile ModelInboxFileFromInboxFile(UPInboxFile inboxFile) { UPMInboxFile upmInboxFile = new UPMInboxFile(StringIdentifier.IdentifierWithStringId(inboxFile.Path)) { Path = inboxFile.Path, URL = inboxFile.URL }; #if PORTING upmInboxFile.Name = inboxFile.Path.LastPathComponent(); Exception attributesErr; NSDictionary fileAttributes = NSFileManager.DefaultManager().AttributesOfItemAtPathError(inboxFile.Path, attributesErr); if (attributesErr) { DDLogError("UPInBoxPageModelController error no fileAttributes: %@", fileAttributes); } NSNumber fileSizeNumber = fileAttributes.ObjectForKey(NSFileSize); upmInboxFile.Size = fileSizeNumber.LongLongValue(); upmInboxFile.FormattedSize = NSByteCountFormatter.StringFromByteCountCountStyle(upmInboxFile.Size, NSByteCountFormatterCountStyleFile); upmInboxFile.Date = fileAttributes.ObjectForKey(NSFileCreationDate); // Cant use TimeZone here. Called before Login and server independent. upmInboxFile.FormattedDate = UPInBoxPageModelController.UpDateFormatter().StringFromDate(upmInboxFile.Date); UIDocumentInteractionController interactionController = UIDocumentInteractionController.InteractionControllerWithURL(inboxFile.URL); ArrayList icons = interactionController.Icons; //upmInboxFile.Icon = icons.LastObject(); // Adding largest Icon available #endif upmInboxFile.MimeTye = UPInboxFileManager.MimeTypeForPath(upmInboxFile.Path); upmInboxFile.Color = UPInBoxPageModelController.ColorForMimeType(upmInboxFile.MimeTye); return(upmInboxFile); }
/// <summary> /// Deletes the file with URL. /// </summary> /// <param name="inboxFileURL">The inbox file URL.</param> public static void DeleteFileWithURL(Uri inboxFileURL) { #if PORTING Exception deleteError; NSFileManager.DefaultManager().RemoveItemAtURLError(inboxFileURL, deleteError); if (deleteError == null) { DDLogError("Error deleting inbox file %@", deleteError); } else { Messenger.Default.Send(InboxFileManagerMessage.FileRemovedFromInbox(inboxFileURL.ToString())); } #endif }
static iCloudPrefs() { if (CoreXT.IsDevice) { // get id from user defaults _userDefaults = NSUserDefaults.StandardUserDefaults(); iCloudID = _userDefaults.Object(ID_KEY) as string; store = NSUbiquitousKeyValueStore.DefaultStore(); store.DidChangeExternally += _OnStoreChanged; NSFileManager.DefaultManager().UbiquityIdentityDidChange += _Init; CoreXT.ApplicationResumed += _Init; _Init(); } }
/// <summary> /// Currents the inbox file manager. /// </summary> /// <returns></returns> public static UPInboxFileManager CurrentInboxFileManager() { if (defaultManager == null) { defaultManager = new UPInboxFileManager(); #if PORTING defaultManager.InboxPath = UPPathService.DocumentPath().StringByAppendingPathComponent("writeableInbox"); defaultManager.RealInboxPath = UPPathService.DocumentPath().StringByAppendingPathComponent("Inbox"); if (!NSFileManager.DefaultManager().FileExistsAtPath(defaultManager.InboxPath)) { NSError error = null; NSFileManager.DefaultManager().CreateDirectoryAtPathWithIntermediateDirectoriesAttributesError(defaultManager.InboxPath, false, null, error); } #endif } return(defaultManager); }
private void OnCloudIdentityChanged(NSNotification obj) { Debug.Log("OnCloudIdentityChanged"); // In order to see if the current iCloud identity has changed // Check the current token against the last one // Tokens are opaque (no public properties). All you can do is compare them var NextToken = NSFileManager.DefaultManager().UbiquityIdentityToken; if (Token == NextToken) { Debug.Log("The cloud identity has not changed"); } else { Debug.Log("The cloud identity has chnaged"); } // If you wanted to unsubscribe from the notification you would do so like.. CKContainer.RemoveAccountChangedNotificationObserver(Unsubscriber); }