public void IsExcludedFromBackupKey() { // NOTE: this test was failing with either NullReferenceException or InvalidCastException // when we used CFBoolean as a NSObject (i.e. CFBoolean.TrueObject). The test order execution // was important to track this down NSObject value; Assert.True(NSBundle.MainBundle.ExecutableUrl.TryGetResource(NSUrl.IsExcludedFromBackupKey, out value), "MainBundle"); Assert.That(value, Is.TypeOf(typeof(NSNumber)), "NSNumber"); Assert.That((int)(value as NSNumber), Is.EqualTo(0), "0"); string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "DoNotBackupMe-NSUrl"); try { File.WriteAllText(filename, "not worth a bit"); using (NSUrl url = NSUrl.FromFilename(filename)) { Assert.True(url.TryGetResource(NSUrl.IsExcludedFromBackupKey, out value)); Assert.That((int)(value as NSNumber), Is.EqualTo(0), "DoNotBackupMe-0"); url.SetResource(NSUrl.IsExcludedFromBackupKey, (NSNumber)1); Assert.True(url.TryGetResource(NSUrl.IsExcludedFromBackupKey, out value)); Assert.That((int)(value as NSNumber), Is.EqualTo(1), "DoNotBackupMe-1"); NSError error; NSDictionary dict = url.GetResourceValues(new NSString [] { NSUrl.IsExcludedFromBackupKey }, out error); Assert.Null(error, "error"); Assert.That(dict.Keys [0], Is.EqualTo(NSUrl.IsExcludedFromBackupKey), "Key"); Assert.That((int)(dict.Values [0] as NSNumber), Is.EqualTo(1), "Value"); } } finally { // otherwise the attribute won't reset even if the file is overwritten File.Delete(filename); } }
/// <summary> /// iOS ONLY - To Comply with iOS iCloud backup restrictions /// <para>Makes sure that the no archive attribute is set for this url in Documents.</para> /// </summary> protected virtual void ExcludeFromBackup (NSUrl filePathURL) { filePathURL.SetResource(NSUrl.IsExcludedFromBackupKey, (NSNumber.FromBoolean(true))); }