public NSUrl?[]? GetResourceUrls(string resourceType, string subDirName, string localizationName) { if (String.IsNullOrEmpty(resourceType)) { throw new ArgumentException(nameof(resourceType)); } if (String.IsNullOrEmpty(localizationName)) { throw new ArgumentException(nameof(localizationName)); } var resourceTypeHandle = CFString.CreateNative(resourceType); var dirNameHandle = CFString.CreateNative(string.IsNullOrEmpty(subDirName) ? null : subDirName); var localizationNameHandle = CFString.CreateNative(localizationName); try { var rv = CFBundleCopyResourceURLsOfTypeForLocalization(Handle, resourceTypeHandle, dirNameHandle, localizationNameHandle); return(CFArray.ArrayFromHandleFunc(rv, (handle) => Runtime.GetNSObject <NSUrl> (handle, true), true)); } finally { CFString.ReleaseNative(resourceTypeHandle); CFString.ReleaseNative(dirNameHandle); CFString.ReleaseNative(localizationNameHandle); } }
public static CFBundle[]? GetAll() { // as per apple documentation: // CFBundleGetAllBundles // // 'This function is potentially expensive and not thread-safe' // // This means, that we should not trust the size of the array, since is a get and // might be modified by a diff thread. We are going to clone the array and make sure // that Apple does not modify the array while we work with it. That avoids changes // in the index or in the bundles returned. using (var cfBundles = new CFArray(CFBundleGetAllBundles(), false)) using (var cfBundlesCopy = cfBundles.Clone()) { return(CFArray.ArrayFromHandleFunc <CFBundle> (cfBundlesCopy.Handle, (handle) => new CFBundle(handle, false), false)); } }
public static CFBundle[]? GetBundlesFromDirectory(NSUrl directoryUrl, string bundleType) { if (directoryUrl is null) // NSUrl cannot be "" by definition { throw new ArgumentNullException(nameof(directoryUrl)); } if (String.IsNullOrEmpty(bundleType)) { throw new ArgumentException(nameof(bundleType)); } var bundleTypeHandle = CFString.CreateNative(bundleType); try { var rv = CFBundleCreateBundlesFromDirectory(IntPtr.Zero, directoryUrl.Handle, bundleTypeHandle); return(CFArray.ArrayFromHandleFunc(rv, (handle) => new CFBundle(handle, true), true)); } finally { CFString.ReleaseNative(bundleTypeHandle); } }