Posts

Post not yet marked as solved
2 Replies
Done. FB11785400
Post not yet marked as solved
1 Replies
It's a swift answer, but you may be able to work it out for c++. https://developer.apple.com/forums/thread/678914
Post marked as solved
1 Replies
I got an answer on SO. As it turns out I did not understand the use of isReleasedWhenClosed setting. By changing it from true to false, I no longer have crashes when I close the window and make it nil.
Post not yet marked as solved
1 Replies
Maybe this can help someone in the future as I am sure you've already worked this out after 5 years. I use this to get album artwork that is embedded in the MP3 file (all my music in my library is MP3 music).       let playerItem = AVPlayerItem(url: mp3URL)       let mp3Details = playerItem.asset.metadata       for item in mp3Details {         guard let key = item.key?.description, let value = item.value else {           continue         }         /*          TPE1 = Album artist          TPE2 = Artist          USLT = Lyrics          COMM = Comments          TCON = Genre          TRCK = Track of tracks          TCOM = Composer          TSSE = Encoder          TPOS = Disk of Disks          TDRC = Year released          TALB = Album Name          TBPM = Beats per minute          */         switch key {         case "***2": mp3Info["title"] = value as? String ?? nil         case "TPE1": mp3Info["artist"] = value as? String ?? nil         case "APIC" where value is NSData : mp3Info["artwork"] = NSImage(data: (value as! NSData) as Data) ?? nil         case "TALB": mp3Info["album"] = value as? String ?? nil         case "USLT": mp3Info["lyrics"] = value as? String ?? nil         case "TBPM": mp3Info["bpm"] = value as? Int ?? nil         default: continue         }       } Of course, this will probably not work on downloaded artwork, since that is an Apple product/service. But if you have MP3 files and you add artwork manually, like I do for my music, then this should work for retrieval.
Post not yet marked as solved
24 Replies
I don't know what the actual solution would be, but I imagine adding an optional notification name parameter to FileManager would be an easy solution i.e. FileManager.default.copyItem(_ at: URL, _ to: URL, _ notification: Notification.Name?). This way if someone wanted to observe that notification they can query the object or userInfo to get bytes written and time remaining and create any kind of progress status they wanted. I've been digging into this myself and would like to find some kind of solution whether it be notifications, or the ability to perform KVO of FileManager while it working.
Post marked as solved
2 Replies
Hmmm... Going back to that page and reading again I am now wondering if this is just a type-o? Maybe the documentation should read "...and a URL for the appropriateFor parameter which determines the volume of the returned URL." ??? If that's the case, then I think I understand the purpose of this parameter.
Post not yet marked as solved
2 Replies
Swift 5.5.1 I know this is old and for iOS, but it may help someone who is trying to figure this out and comes across this question. I don't know if the same notification works in iOS, but there should be a similar way if not. You can use the notification NSApplication.didChangeScreenParametersNotification import Cocoa class ViewController: NSViewController { var externalDisplayCount:Int = 0 override func viewDidLoad() { super.viewDidLoad() externalDisplayCount = NSScreen.screens.count setupNotificationCenter() } func setupNotificationCenter() { NotificationCenter.default.addObserver( self, selector: #selector(handleDisplayConnection), name: NSApplication.didChangeScreenParametersNotification, object: nil) } @objc func handleDisplayConnection(notification: Notification) { if externalDisplayCount < NSScreen.screens.count { print("An external display was connected.") externalDisplayCount = NSScreen.screens.count } else if externalDisplayCount > NSScreen.screens.count { print("An external display was disconnected.") externalDisplayCount = NSScreen.screens.count } else { print("A display configuration change occurred.") } } } Notice that the final else is there and will be triggered whenever something changes with any of the connected displays configuration, such as toggling fullscreen mode on a display, or through system preferences.
Post not yet marked as solved
2 Replies
The first thing that comes to mind would be using a notification. func downloadFiles(remoteFolder rf:String, localFolder lf:String, completion: @escaping (_ success:Bool, _ err: String) -> Void) { DispatchQueue.global(qos:.background).async { let fileName:String = (use whatever setter you have from your loop) NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateDownloadFileName", object: nil, userInfo: ["fileName":fileName])) ... DispatchQueue.main.async { completion(successBool, errorMsg) } } } In your ViewController: let myLabel = NSTextField(labelWithString: "") override func viewDidLoad() { setupNotificationCenter() } func updateDownloadFileName(notification: Notification) { if let data = notification.userInfo as? [String:String] { if let string = data["fileName"] { myDownloadLabel.stringValue = string } } } func setupNotificationCenter() { NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "updateDownloadFileName"), object: nil, queue: nil, using: updateDownloadFileName) } If you don't want to use Notifications then you could pass the Label to the method and update the stringValue through a dispatch to the main thread: func downloadFiles(remoteFolder rf:String, localFolder lf:String, myLabel:NSTextField, completion: @escaping (_ success:Bool, _ err: String) -> Void) { DispatchQueue.global(qos:.background).async { let fileName:String = (use whatever setter you have from your loop) DispatchQueue.main.async { myLabel.stringValue = fileName } ... DispatchQueue.main.async { completion(successBool, errorMsg) } } }
Post marked as solved
1 Replies
As pointed out on another site, the problem was caused by me setting the styleMask as .borderless without .titled, which prevents the window from becoming key or main according to this. Here's my updated code that works in Swift 5.5: import Cocoa class ViewController: NSViewController {     var externalDisplay: NSScreen?     var fullScreenWindow: NSWindow?     var fullScreenView: NSView?     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     }     override var representedObject: Any? {         didSet {         // Update the view, if already loaded.         }     }     @IBAction func showExternalDisplayButtonClicked(sender: Any?) {         // Open the external display window if one is present         if NSScreen.screens.count > 1 {             externalDisplay = NSScreen.screens.last             let mask: NSWindow.StyleMask = [.titled, .closable, .miniaturizable, .resizable, .borderless]             fullScreenWindow = NSWindow(contentRect: externalDisplay!.frame, styleMask: mask, backing: .buffered, defer: true, screen: externalDisplay)             fullScreenWindow!.level = .normal             fullScreenWindow!.isOpaque = false             fullScreenWindow!.hidesOnDeactivate = false             fullScreenWindow!.backgroundColor = .red             let viewRect = NSRect(x: 0, y: 0, width: externalDisplay!.frame.width, height: externalDisplay!.frame.height)             fullScreenView = NSView(frame: viewRect)             fullScreenWindow!.contentView = fullScreenView             fullScreenView?.window?.toggleFullScreen(self)         }     } }
Post not yet marked as solved
17 Replies
Had the same issue today. Went to the developer site and signed in. Turns out I needed to agree to the new developer agreement. Once I did that, everything worked as usual. Apple could have added an appropriate error text to tell me that...
Post not yet marked as solved
9 Replies
@OOPer, your solution doesn't work for me. This is now showing up on my console, but not causing a crash. The audio (mp3 file) still plays as expected. I use AVAudioPlayer from AVFoundation in my code on macOS Big Sur, XCode 12.3, Swift 5.3. I building a macOS app, not iOS. I declare my player as var player:AVAudioPlayer? (I had it also as AVAudioPlayer!) and both produce the same console message above. Like I wrote above, the audio still plays, but I would like to get this resolved so the message no longer appears. I stepped through my code and the error is appearing immediately upon calling player?.prepareToPlay() method. EDIT: Subsequent calls to this method does not reproduce the error in the console. It is only happening upon the initial call to this method. If I play a subsequent mp3 file it doesn't repappear. if player?.prepareToPlay() != nil { Thanks to anyone who can suggest how to resolve this.
Post marked as solved
6 Replies
@Claude31, that solution only disables the scrollWheel. It does not turn off the scrollbars in the enclosingScrollView, and the user can still grab the scroll bars and drag the webView up or down or left to right. I even tried webView.enclosingScrollView.hasHorizontalScroller = false and webView.enclosingScrollView.hasVerticalScroller = false and that doesn't remove the scroll bars either.
Post not yet marked as solved
2 Replies
I finally got the video to play by going to the Signing &amp; Capabilities tab in the Project Settings and checked Outgoing Connections (Client) under App Sandbox. Apple should make note of this requirement in their guide. However, I am still getting the following errors in the console: 2021-03-30 14:45:34.347266-0500 Streamer[12701:657907] [plugin] AddInstanceForFactory: No factory registered for id CFUUID 0x600003974980 F8BB1C28-BAE8-11D6-9C31-00039315CD46 2021-03-30 14:45:34.474219-0500 Streamer[12701:657916] validateSessionInfo: bundleID is invalid. Please specify the bundleID for kRTCReportingSessionInfoClientBundleID 2021-03-30 14:45:34.475221-0500 Streamer[12701:657894] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:34.475366-0500 Streamer[12701:657894] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:34.507482-0500 Streamer[12701:657907] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-30 14:45:34.513188-0500 Streamer[12701:657907] [logging] volume does not support data protection, stripping SQLITE_OPENFILEPROTECTION* flags 2021-03-30 14:45:34.654719-0500 Streamer[12701:657415] Metal API Validation Enabled 2021-03-30 14:45:35.304861-0500 Streamer[12701:657894] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:35.963419-0500 Streamer[12701:657895] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:40.709591-0500 Streamer[12701:657896] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:40.809438-0500 Streamer[12701:657895] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:41.075516-0500 Streamer[12701:657896] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:41.787596-0500 Streamer[12701:657894] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd} 2021-03-30 14:45:42.762731-0500 Streamer[12701:657896] [connection] nw_connection_add_timestamp_locked_on_nw_queue [C1] Hit maximum timestamp count, will start dropping events
Post not yet marked as solved
3 Replies
Did you ever get this figured out? I'm facing the same issue on macOS.
Post not yet marked as solved
2 Replies
Has anyone tried following the referenced Apple document and successfully ran it in macOS Big Sur?