I am using NetFS's NetFSMountURLAsync api to mount SMB share in mac os app. I am able to mount the share however this share is not automatically appearing in Finder's sidebar. I tried using LSSharedFileListInsertItemURL to make the mount point available in Finder's side bar however facing crash on line,
kLSSharedFileListItemBeforeFirst.takeRetainedValue()
from below code snippet.
let itemType: CFString = kLSSharedFileListFavoriteItems.takeRetainedValue()
if let list: LSSharedFileList = LSSharedFileListCreate(nil, itemType, nil)?.takeRetainedValue() {
let inPropertiesToSet: CFMutableDictionary = CFDictionaryCreateMutable(nil, 1, nil, nil)
CFDictionaryAddValue(inPropertiesToSet, unsafeBitCast(kLSSharedFileListVolumesNetworkVisible, to: UnsafeRawPointer.self), unsafeBitCast(kCFBooleanTrue, to: UnsafeRawPointer.self))
let driveUrl = URL(fileURLWithPath: mountPoint)
let shareUrl: CFURL = driveUrl as CFURL
if let item: LSSharedFileListItem = LSSharedFileListInsertItemURL(
list,
kLSSharedFileListItemBeforeFirst.takeRetainedValue(),
nil, iconRef, shareUrl, inPropertiesToSet, nil) {
let itemRefId = LSSharedFileListItemGetID(item)
let itemRefIdStr = "\(itemRefId)"
userDefaults.set(itemRefIdStr, forKey: mountPoint)
}
}
Anything wrong in above code? Also since this api is deprecated is there any alternative API to achieve this. The goal is to make the mount point available in Finder's sidebar so that user can easily access it.