Post

Replies

Boosts

Views

Activity

Storing SwiftUI Views to operate on it
I am creating a UIKit application but that contains SwiftUI Views embedded using the hostingcontroller. I have a particular approach for it..but it requires instantiating a swiftUI view, creating a hostingcontroller object from it and storing a reference to it. So that later If I wanted to update the view, I can simply get the reference back and update the swiftUI view using it. I wanted to understand what does apple recommends on this. Can we store a swiftUI instance? Does it cause any issue or it is okay to do so?
0
0
131
2w
Unable to update NSProgressIndicator for the dock Icon
I have created a progress indicator to simulate some progressing download task in the dock icon. However, I can see the progress bar appearing in the dock icon but it is not getting updated when I invoked the updateProgress() method. Ideally it should have updated it, and I m not able to figure out the reason? I have creating the same NSProgressIndicator on an NSWindow and it works to update the progress bar with the same code. Anything that I m missing to understand here? Below is the code I m using: class AppDelegate: NSObject, NSApplicationDelegate { var progressIndicator: NSProgressIndicator! let dockTile = NSApp.dockTile func applicationWillFinishLaunching(_ notification: Notification) { // Step 1: Create a progress bar (NSProgressIndicator) progressIndicator = NSProgressIndicator(frame: NSRect(x: 10, y: 10, width: 100, height: 20)) progressIndicator.isIndeterminate = false progressIndicator.minValue = 0.0 progressIndicator.maxValue = 100.0 progressIndicator.doubleValue = 0.0 progressIndicator.style = .bar dockTile.contentView = progressIndicator dockTile.display() //// Update the progress bar for demonstration DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.updateProgress(50) } } func updateProgress(_ value: Double) { progressIndicator.doubleValue = value NSApp.dockTile.display() } }
0
0
223
Oct ’24
NSClickGestureRecognizer not working to invoked the registered event method
I have created a NSView inside the NSWindow. I m trying to identify when the view gets clicked by the user. For this I m using NSClickGestureRecognizer, but the registered method is not getting invoked. I have tried adding this for other widgets like button but it does not work either. Am I missing something? class SelectionList :NSObject, NSTextFieldDelegate{ let containerView = NSView() func createSelectionList (pWindow: NSWindow) { // created container View ... let clickRecognizer = NSClickGestureRecognizer() clickRecognizer.target = self clickRecognizer.buttonMask = 0x2 // right button clickRecognizer.numberOfClicksRequired = 1 clickRecognizer.action = #selector(ClickGestured) containerView .addGestureRecognizer(clickRecognizer) } @objc func clickRecognizer() { print("clicked") } }
0
0
208
Sep ’24
"App not responding" in the dock menu
I have a bundled macOS application. This is a non-interactive application where I m performing some task on the worker thread while the main thread waits for this task to be completed. Sometimes this task can be time consuming. I have observed that when I run the application using the bundle( like double click or open command) I can see the OS marking my application as not responding( this is evident as the app icon toggles in the dock and then it states not responding). Although If I run the unix executable in the bundle, the app runs and I do not see the not responding status anywhere. I wanted to understand If this is happening because my main thread is in a waiting state? If yes, what could I do to resolve it because my application logic demands the main thread to wait for the worker thread to complete its task. Is there some way to use some event loop like GCD? Note: I cannot use the delegates(Appkit) event loop because my application will be run in non-GUI context.
5
0
544
Jul ’24
Using bundled applications(.app file) as daemon/Agent
I have a .app file that I want to run as a daemon. Now there are two ways of running .app as a daemon/agent in macOS. using .app file : I can specify this in the daemon plist as: <key>ProgramArguments</key> <array> <string>/usr/bin/open</string> <string>/Applications/myApp.app</string> </array> using unix exe within .app file <key>ProgramArguments</key> <array> <string>myApp.app/Content/MacOS/MyApp</string> </array> Basically I wanted to know what is the Apple recommendation on how we should be creating daemon plist. For point 2, is it appropriate to use the unix executable within bundle?Will it not cause any issue in the running application? Is will be helpful if there is some apple documentation to support this.
1
0
368
Jul ’24
representation error in swift generated header
I have a public swift function with the below declaration : public func InternalMain (_ pNumOfArgs : Int32, _ pCmdlineArgs : UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> Int32 {..} I need this function as public because I need to invoke in from a different library. But the above declaration produces an error in my generated swift header i.e '-swift.h' file because 'UnsafeMutablePointer<UnsafeMutablePointer?>' type cannot be represented in the swift generated header. Can someone help how do I get past this. This is a class independent function and I tried using the '@nonobj' to prevent this from getting in the generated header but it still gives an error.
2
0
627
Jun ’24
Detecting sleep/wake event in IOS
In IOS, when the device is kept idle for some time, the screen turns off and the device enters sleep mode. It also enters sleep mode when we press the power button to turn the screen off. In my application, I wanted to detect If the device has entered/exited the sleep mode. I have followed the below links but some of these ways like observing 'Darwin notifications' is no longer allowed by apple. Other ways consider the device being locked as sleep mode, which is not precisely correct. Is there a way to correctly determine this? Please share the apple documentation links if this is possible. https://stackoverflow.com/questions/14191980/detect-screen-on-off-from-ios-service/14208787#14208787 https://nemecek.be/blog/104/checking-if-device-is-locked-or-sleeping-in-ios
2
1
894
Jan ’24
'open' command in macOS fails to launch .app file in non GUI environment
I have a bundled application(.app file) in macOS which is a non-interactive application. This app does not link to any GUI frameworks and I am able to launch it using the 'open' command in a normal GUI login session. However, when I perform ssh login to that user and then If I try to launch the application, it fails to launch. I assume that this is happening because my ssh session is a non-GUI session, and 'open' command is due to some reason failing to run in a non-GUI environment, but I m not sure. Can someone help me understand why is this happening?
1
0
363
May ’24
Can we add an action to the 'Shortcuts' app in macOS using 'Intents extension'?
I have macOS application and I want to provide an action for it in the 'Shortcuts' app QuickAction list. I was using InApp handling to present my intent created in the intent.intentdefinition file as action in the shortcuts app and it was working. However, this action perform a very lightweight task so I intent to have the action implemented as an extension in my xcode project. According to my minimum deployment(i.e macOS 11.0) I found that 'Intents Extension' could be used. I have added the 'Intents extension' target to my main application and created an intent using the intent.intentdefinition file. However, my intent does not appear in the shortcuts app. I have verified it multiple time to ensure I am not missing anything, but still the intent is not present in the shortcuts app action. I wanted to be know, Is this even possible? cause this apple documentation only mentions about iOS and watchOS app. It also does not mention If our custom intent(created using Intents extension) in the intents extension can be exposed to the shortcuts app. For macOS 13.0+, I have used the 'AppIntents extension' and I m able to achieve the same. So, I suppose the same should be possible using the 'Intents extension'
1
0
517
May ’24
How to identify If my executable is launched as User Agent in macOS
I have an executable in macOS that I m launching as a User Agent. The same executable can be launched in multiple ways like either user can directly click the exe to launch it, or user can launch it from the terminal using ./ etc. One similar way is when the user launches the exe as a User Agent(i.e daemon in user session). In this scenarios, I want to identify in my exe If my user has launched it as agent to perform certain task. I wanted to know how can I accurately determine this? I have tried figuring out If there is some unique session that agents operate in, but I could not find anything. Can someone help here? Is this even possible?
1
0
445
May ’24
'openAppWhenRun' property causing AppIntentsExtension to fail
I have added an "App Intents Extension" target to my main application in macOS. This generated the below two files: TWAppIntent.swift import AppIntents struct TWAppIntent: AppIntent { static var title: LocalizedStringResource = "TWAppIntentExtension" static var parameterSummary: some ParameterSummary { Summary("Get information on \(\.$TWType)") } //launch app on running action static var openAppWhenRun: Bool = true // we can have multiple parameter of diff types @Parameter(title: "TWType") var TWType: String func perform() async throws -> some IntentResult & ReturnsValue<String> & ProvidesDialog { return .result(value: TWType, dialog: "Logged break.") } } TWAppIntentExtension.swift import AppIntents @main struct TWAppIntentExtension: AppIntentsExtension { } I m able to build the extension target and I my intent action is available in the shortcuts app. However, on launching a shortcut with the above created intent action. I m getting the below popups: I have identified what is causing this error. Setting the openAppWhenRun to true is causing this error. I don't get this when it is set to false. This property is supposed to launch the application, but can someone help me understand why is it happening? This is only causing the error when using this property for AppIntent Extension and not for In app handling for the AppIntent. Can we not launch our application from AppIntent extension?
1
2
557
May ’24
Xcode ‘C++ and Objective-C Interoperability’ build setting not getting set
I m trying to create an xcode project with cpp-swift interoperability(introduced in xcode15) using cmake xcode generator. I m able to invoke cpp code in swift and vice-versa but when opening the project in xcode, the build setting for 'C++ and Objective-C Interoperability' is still set to 'C/Objective C' like in image below. I want to set it to 'C++/Objective-C++'. I m using the below cmake for this: . . add_library(cxx-support ./Sources/CxxSupport/Student1.cpp ./Sources/CxxSupport/Teacher.swift ) #include the directory to access modulemap content target_include_directories(cxx-support PUBLIC ${CMAKE_SOURCE_DIR}/Sources/CxxSupport) target_compile_options(cxx-support PUBLIC "$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>" ) . . I Have also tried the below in cmake, but it didn't work. #set(SWIFT_OBJC_INTEROP_MODE "objcxx" CACHE STRING "") #target_compile_options(cxx-support PUBLIC #"SWIFT_OBJC_INTEROP_MODE=objcxx") Any help on how this can be achieved?
1
0
940
Oct ’23
Shutdown event in macOS
I wanted to identify the shutdown event in macOS, so that If my application is running and the user performs a system shutdown then my application could be notified of the shutdown event and perform finalization. I came across NSWorkspaceWillPowerOffNotification which is exactly what I require, however, I created a sample application to observe for this notification. Is is observed that right before the system shuts down, the OS terminates my application invoking applicationWillTerminate(_:) delegate and the observer method for 'NSWorkspaceWillPowerOffNotification' is not invoked. I could perform my finalization in the applicationWillTerminate, but I wanted to know why is the observer not getting invoked. Also why is NSWorkspaceWillPowerOffNotification, even provided by apple when it invoked the termination delegate before shutdown? below is how I m adding the observer: NotificationCenter.default.addObserver(forName: NSWorkspace.willPowerOffNotification, object: nil, queue: nil, using: AppDelegate.handlePowerOffNotification) Below is my observer function, which just logs: public static func handlePowerOffNotification(_ notification: Notification) { NSLog (AppDelegate.TAG + "System will power off soon! Perform any necessary cleanup tasks.") // custom logger to log to a file TWLog.Log ("System will power off soon! Perform any necessary cleanup tasks.") }
3
0
779
May ’24