Posts

Post not yet marked as solved
3 Replies
527 Views
I am trying to open a cocoa GUI application from authorization plugin which runs during login. I have placed the application in /Library/Application Support/MyFolder/Example.app. I am using below environment and code to open the application.Environment:OSX: 10.14.5 (Mojave)Xcode: 11.2.1Swift: 4.2Code:let task = Process.init() task.launchPath = "/Library/Application Support/MyFolder/Example.app/Contents/MacOS/Example" task.arguments = ["Hi", "Hello"] task.launch() task.waitUntilExit()While the above code works perfectly fine when trying to open process from normal cocoa application it doesn't when I am trying the same from a bundle project which is used as an authorization plugin (https://developer.apple.com/documentation/security/authorization_plug-ins/using_authorization_plug-ins)Crash Report:Process: Example [2236]Path: /Library/Application Support/MyFolder/Example.app/Contents/MacOS/ExampleIdentifier: com.MyFolder.mfa1.ExampleVersion: 1.0 (1)Code Type: X86-64 (Native)Parent Process: SecurityAgent [2223]Responsible: Example [2236]User ID: 92Date/Time: 2020-03-23 01:23:26.652 +0530OS Version: Mac OS X 10.14.5 (18F132)Report Version: 12Bridge OS Version: 3.5 (16P5125)Anonymous UUID: 42E41D19-877E-2567-CBFA-B03BAF4D4DE8Time Awake Since Boot: 8800 secondsSystem Integrity Protection: enabledCrashed Thread: 1 Dispatch queue: com.apple.root.default-qosException Type: EXC_BAD_INSTRUCTION (SIGILL)Exception Codes: 0x0000000000000001, 0x0000000000000000Exception Note: EXC_CORPSE_NOTIFYTermination Signal: Illegal instruction: 4Termination Reason: Namespace SIGNAL, Code 0x4Terminating Process: exc handler [2236]Application Specific Information:XPC API Misuse: Attempt to look up cross UID boundaries by unprivileged process.Application Specific Signatures:API MisuseFor full crash report look at the https://pastebin.com/ZtRrpMFe
Posted Last updated
.
Post not yet marked as solved
5 Replies
3.3k Views
I am working on a bundle project in swift for MacOS which is used as an authorization plugin which runs at login (https://developer.apple.com/documentation/security/authorization_plug-ins/using_authorization_plug-ins) and in the bundle project I am doing API request call using URLSession.shared.dataTask and in the call back I receive, I am trying to update the UI and as updating UI has to be done using main thread I am using DispatchQueue.main.async and the code inside DispatchQueue.main.async is never getting executed! This works perfectly fine in a normal macOS Cocoa application but the problem persists with Bundle project for macOS.CODE:class MainForm: NSWindowController{ public var bodyParams: [String: Any]? override func windowDidLoad() { super.windowDidLoad() testfetch{ (Response) in os_log("In completion handler response: %@", Response) //code to update some UI follows } } func testfetch(completion: @escaping (Response) -> ()){ os_log("Is this mainthread in testFetch %@", Thread.isMainThread ? "Yes" : "No") os_log("Current thread testFetch %@", Thread.current) let url = URL(string: "https://example.com")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Accept") request.setValue("application/json", forHTTPHeaderField: "Content-Type") bodyParams = ["username": "******", "password": "*****"] if let bodyParams = bodyParams { guard let body = try? JSONSerialization.data(withJSONObject: bodyParams, options: []) else { return } request.httpBody = body let task = URLSession.shared.dataTask(with: request) {(data, response, error) in guard let data = data else { os_log("Data not recieved!!") return } os_log("Is this mainthread in dataTask %@", Thread.isMainThread ? "Yes" : "No") os_log("Current thread in dataTask %@", Thread.current) os_log("Data recieved in testFetch: %@", String(data: data, encoding: .utf8)!) do{ let receivedData = try JSONDecoder().decode(Response.self, from: data) DispatchQueue.main.async{ os_log("Is this mainthread in main.async %@", Thread.isMainThread ? "Yes" : "No") os_log("Current thread in main.async %@", Thread.current) completion(receivedData) } } catch let Err{ os_log("Error is: %@", Err as! String) } } task.resume() } } struct Response: Codable { let name, age, status: String } }Logs:Is this mainthread in testFetch? YesCurrent thread testFetch <NSThread: 0x7f9176001c30>{number = 1, name = main}Is this mainthread in dataTask NoCurrent thread in dataTask <NSThread: 0x7f9173dc2080>{number = 4, name = (null)}Data recieved in testFetch: {"name":"JohnDoe", "age": "**", "status": "single"}So the logs in `DispatchQueue.main.async` and completion handler are never getting printed. I am quite new to swift and async programming any help would be much appreciated!
Posted Last updated
.