Inter-process communication

RSS for tag

Share data through Handoff, support universal links to your app's content, and display activity-based services to the user using inter-process communication.

Inter-process communication Documentation

Posts under Inter-process communication tag

44 Posts
Sort by:
Post marked as solved
4 Replies
1.6k Views
I try to exclude some activities from UIActivity. It works as expected when exclusion is done directly with the activity, as with: UIActivity.ActivityType.message, UIActivity.ActivityType.airDrop but not when activity is declared with an init as with: UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"), UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share"), So, with the following code: let excludedActivityTypes = [ UIActivity.ActivityType.message, UIActivity.ActivityType.airDrop, UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"), UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share") ]         let activityVC = UIActivityViewController(activityItems: [modifiedPdfURL], applicationActivities: nil)          activityVC.excludedActivityTypes = excludedActivityTypes message and airDrop do not show, but WhatsApp and IFTTT still show. I have tested with         activityVC.completionWithItemsHandler = { (activity, success, modifiedItems, error) in             print("activity: \(activity), success: \(success), items: \(modifiedItems), error: \(error)")         } that WhatsApp and IFTTT services are effectively the ones listed here. When selecting WhatsApp, print above gives: activity: Optional(__C.UIActivityType(_rawValue: net.whatsapp.WhatsApp.ShareExtension)), success: false, items: nil, error: nil
Posted
by Claude31.
Last updated
.
Post not yet marked as solved
9 Replies
9.9k Views
if let url = URL(string:UIApplication.openSettingsURLString) { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } }As from apple doc i use above method to open iphone setting from app but unfortuantely its going to app setting rather than IphoneSetting I am using swift version 4.2 not sure whats the issue
Posted
by Peter2131.
Last updated
.
Post not yet marked as solved
6 Replies
388 Views
In my project I have a host application and a husk application. What I want to do is, every time the user launches a new view in the host application, I want to create one more dock icon by launching another instance of husk application. Then the husk application behaves like it is the view itself by monitoring the event of click/quit and send them to the host application through XPC. The XPC tutorial tells me an XPC service embedded in an application is invisible to the processes outside the bundle. To communicate between two foreground applications it seems that I need to create a third helperTool/agent/daemon which venders a Mach/XPC service. But I wonder if I can put husk application inside the bundle of the hose application. So they can directly connect to the XPC service which is also embedded in the same bundle. If the answer is no, maybe NSDistributedNotificationCenter is much better and simpler in my scenario?
Posted
by Cecil1345.
Last updated
.
Post marked as solved
1 Replies
162 Views
Hello, On macOS, I can include a second executable in the app bundle, which the main executable can launch and communicate with via pipes (standard input/output). I've done this before (with app sandbox inheritance). I've read on other forums that this is not possible on iOS. Is that correct? I tried popen() and it always fails with the error "Operation not permitted." 😔 I just wanted to confirm before I move on to using frameworks. Thanks for your time.
Posted Last updated
.
Post marked as solved
4 Replies
321 Views
Hi, I am currently building my own VPN application using NetworkExtension's PacketTunnelProvider. I want to send information from the PacketTunnelProvider to the ViewController when a VPN connection fails and to tell the user why. The code now is as shown below. When the startTunnel() being overwritten is executed, somehow NotificationCenter.default.post(name: NSNotification.Name.NEVPNStatusDidChange, object: nil) is executed and VPNStatusDidChange(_ notification: Notification?) in the ViewController is called and displays some message. I tried to do the same thing by writing NotificationCenter.default.post(name: NSNotification.Name(rawValue: "testnotify"), object: nil) in the PacketTunnelProvider.swift , but it does not work. What is wrong? Here is a part of current PacketTunnelProvider.swift override func startTunnel(options: [String : NSObject]? = nil, completionHandler: @escaping (Error?) -> Void) {   conf = (self.protocolConfiguration as! NETunnelProviderProtocol).providerConfiguration! as [String : AnyObject]   self.setupWSSession()       DispatchQueue.global().async {     while (self.connectionPhase < 5) {       Thread.sleep(forTimeInterval: 0.5)     }     self.tunToWS()   } NotificationCenter.default.post(name: NSNotification.Name(rawValue: "testnotify"), object: nil) } And here is a part of ViewController.swift override func viewDidLoad() {     super.viewDidLoad()     initVPNTunnelProviderManager()     NotificationCenter.default.addObserver(self, selector: #selector(ViewController.VPNStatusDidChange(_:)), name: NSNotification.Name.NEVPNStatusDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(ViewController.receieve(_:)), name: NSNotification.Name(rawValue: "testnotify"), object: nil)     } @objc func VPNStatusDidChange(_ notification: Notification?) {   print("VPN Status changed:")   let status = self.vpnManager.connection.status   switch status {   case .connecting:     print("Connecting...")     connectButton.setTitle("Disconnect", for: .normal)     break   case .connected:     print("Connected...")     connectButton.setTitle("Disconnect", for: .normal)     break   case .disconnecting:     print("Disconnecting...")     break   case .disconnected:     print("Disconnected...")     connectButton.setTitle("Connect", for: .normal)     break   case .invalid:     print("Invliad")     break   case .reasserting:     print("Reasserting...")     break   } } @objc func receive(_ notification: Notification?) {     print("receive Notification!") }
Posted Last updated
.
Post not yet marked as solved
2 Replies
3.6k Views
I have successfully implemented Universal Links so that a visitor to specific URLs on our site is redirected to one of our apps. It all works well. Alarmingly well, in that it all worked perfectly first time. (I blame the documentation). A question I can't find specifically addressed in the documentation is: what if we have two apps that can both handle a given link? This is in fact our situation. In most cases users will have one or other of the apps installed. The correct behaviour would then be to direct the user to the installed app. In some cases the user will have both apps installed. In that case the ideal behaviour would be to direct the user to what we have defined to be the "main" app. It looks to me as if it is possible to two apps in an apple-app-site-association file, but not having found this in the documentation, I wonder: has anyone on here actually tried this? Did it work as expected?
Posted Last updated
.
Post not yet marked as solved
12 Replies
659 Views
Hi, I’d like to perform client-side certificate authentication from https based connection in macOS. I’m using the method didReceiveChallenge from URLSession. However, I cannot read the keychain directly since my process is running as Daemon, and my client certificate reside in login keychain. So I've followed the guidance from this question https://developer.apple.com/forums/thread/106851, and sent this authentication request to a user-based process which is running in the current user so it has access to the keychain. After I acquire the NSURLCredential object, I’d like to return it back to the Daemon, so it may run the completionHandler with that credential. However, After I successfully create the NSURLCredential in the user process, and send it back using some reply callback. It looks like the object didn’t serialized properly and I get the following error : Exception: decodeObjectForKey: Object of class "NSURLCredential" returned nil from -initWithCoder: while being decoded for key <no key> Here’s my client side code ( I made sure that the server side create a valid NSURLCredential object). and the problem occur after I send the XPC request, right when i’m about to get the callback response (reply) - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler { if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate) { [myXpcService getCertIdentityWithAcceptedIssuers:challenge.protectionSpace.distinguishedNames withReply:^(NSURLCredential *cred, NSError *error) { if (error != nil) { completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil); } else { completionHandler(NSURLSessionAuthChallengeUseCredential, cred); } }]; } Perhaps anybody can tell me what did I do wrong here ? Does XPC is capable to pass complex objects like NSURLCredentials ? thanks !
Posted
by chapo213.
Last updated
.
Post not yet marked as solved
0 Replies
180 Views
We'd prefer our security application not be worked around by the complex task of typing sudo launchctl unload /Library/LaunchDaemons/foo.plist 😄. Is there a way to prevent that? (We're not using ServiceManagement because we need ot control some of the plist entries, sadly.)
Posted
by kithrup.
Last updated
.
Post not yet marked as solved
3 Replies
265 Views
I am trying to pass an array of C-structs to an XPC Service, but the service receives only the first element. Following is the C struct struct MyStruct { char *name; unsigned char v1; unsigned char v2; Status status; // a c-style enum }; and I am using it like this struct MyStruct structs[3] = {{"name1", 0, 0, success}, {"name2", 1,1, success}, {0}}; [[_connectionToService remoteObjectProxy] doSomething:structs]; and doSomething is declared as - (void)doSomething: (struct MyStruct[]) structs; The document Creating XPC Services mentions that C structures and arrays containing only the types listed above are supported, but I am unable to get it to work even for an array of c-strings or ints. Also, there's an API for making synchronous RPC calls but there is no documentation available for it. - (id)synchronousRemoteObjectProxyWithErrorHandler:(void (^)(NSError *error))handler It does seem to block but only if the remote method has a reply block. Is this the expected behaviour? And is it safe to cache the proxy object returned by this method?
Posted Last updated
.
Post not yet marked as solved
1 Replies
213 Views
I refer to this article: https://developer.apple.com/forums/thread/129752 extension Cmd {   static func launch(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {     let group = DispatchGroup()     let pipe = Pipe()     var standardOutData = Data()     group.enter()     let proc = Process()     proc.executableURL = tool     proc.arguments = arguments     proc.standardOutput = pipe.fileHandleForWriting     proc.terminationHandler = { _ in       proc.terminationHandler = nil       group.leave()     }     group.enter()     DispatchQueue.global().async {       // Doing long-running synchronous I/O on a global concurrent queue block       // is less than ideal, but I’ve convinced myself that it’s acceptable       // given the target ‘market’ for this code.       let data = pipe.fileHandleForReading.readDataToEndOfFile()       pipe.fileHandleForReading.closeFile()       DispatchQueue.main.async {         standardOutData = data         group.leave()       }     }     group.notify(queue: .main) {       completionHandler(proc.terminationStatus, standardOutData)     }     try proc.run()     // We have to close our reference to the write side of the pipe so that the     // termination of the child process triggers EOF on the read side.     pipe.fileHandleForWriting.closeFile()   } } run shell : try Cmd.launch(tool: URL(fileURLWithPath: "/usr/bin/which"), arguments: ["docker"]) { (status, outputData) in         let output = String(data: outputData, encoding: .utf8) ?? ""         print("done, status: \(status), output: \(output)")       } the result print: done, status: 1, output:  i had remove sandbox and use this code in my mac app. and return value is empty string. I tried running this script using https://github.com/kareman/SwiftShell and got the same result
Posted Last updated
.
Post not yet marked as solved
5 Replies
385 Views
We are noticing a strange behavior with our app and launchctl, not sure yet if it is only in M1 Monterey Macos. We have a launchctl plist that has not changed for a while that allows the app to restart after a crash via the Keepalive key &amp;lt;key&amp;gt;KeepAlive&amp;lt;/key&amp;gt; &amp;lt;dict&amp;gt; &amp;lt;key&amp;gt;SuccessfulExit&amp;lt;/key&amp;gt; &amp;lt;false/&amp;gt; What we are noticing is that the app crashes and instead of the app reopening via launchctl , an Apple crash report window opens. The app is used in several headless environments and we are trying to understand asap how to deal with this change of behavior. Any input will be helpful. Is there an option in xcode to modify this kind of behavior ? For example set the app to show a crash report instead of launchctl executing. Is there a way to trace why launchctl did not reopen the app ? Does it make a difference if the app is a debug version ? We have noticed no difference between Release and Debug versions, same behavior.
Posted Last updated
.
Post marked as solved
2 Replies
293 Views
I have a few questions regarding daemons. Indeed, even the macos developer center has limited information resources. I want to develop an application daemon that runs after system boot without login. a) a Daemon; Is it a simple console application combined with a plist? Because there are almost no tutorials on daemon development related to xcode. If there is a code sample reference, can you share it here? b) Can daemons be downloaded from the app store? Because there must be a software that I can offer to everyone through the app store. Is the installation automatic like other app store apps? If anyone has experience and can share it, I would be very grateful. c) I am working on an api related to mirroring the screen to android phone. Do you think a daemon has full access to wifi/ble and screen capture APIs? I would be very happy to hear your suggestions.
Posted Last updated
.
Post not yet marked as solved
6 Replies
1.3k Views
Hi, I have a macOS application say Main.app which uses Helper App say Helper.app with UI support. Helper.app is placed inside Main.app/Contents/Library/LoginItems/Helper.app. Helper.app is launched using NSWorkSpace and when user opts to launch Helper.app on login, SMLoginItemSetEnabled is turned ON for Helper.app. Main.app and Helper.app communicate with each other via NSConnection.  Helper app supports set of features based on some Condition and same condition is used to validate a feature in Main.app. Hence, Main.app talks to Helper.app to check if a feature can be validated. 1) Can someone write their version of Helper.app with same bundle identifier as my Helper.app and expose a connection with same name (when my Main.app and Helper.app is not running). 2) Now when Main.app is launched, it get connected to 3rd party Helper.app. There are two versions of Main.app Main.app and Helper.app both are sandboxed and Belong to same group. Main.app and Helper.app both are not sandboxed (But, hardened run time is enabled). Groups are not defined. Thank you. Regards, Deepa
Posted
by Deepa Pai.
Last updated
.
Post not yet marked as solved
1 Replies
440 Views
I'm trying to use task_for_pid in a project but I keep getting error code 5 signaling some kind of signing error. Even with this script I cant seem to get it to work. #include <mach/mach_types.h> #include <stdlib.h> #include <mach/mach.h> #include <mach/mach_error.h> #include <mach/mach_traps.h> #include <stdio.h> int main(int argc, const char * argv[]) {   task_t task;   pid_t pid = argc >= 2 ? atoi(argv[1]) : 1;   kern_return_t error = task_for_pid(mach_task_self(), pid, &task);   printf("%d -> %x [%d - %s]\n", pid, task, error, mach_error_string(error));   return error; } I've tried signing my executables using codesign and also tried building with Xcode with the "Debugging Tool" box checked under hardened runtime. My Info.plist file includes the SecTaskAccess key with the values "allowed" and "debug." Hoping someone can point me towards what I'm missing here. Thanks!
Posted
by Emre_A.
Last updated
.
Post marked as solved
3 Replies
965 Views
Hello, I am facing an issue with NSTask (Process), NSPipe (Pipe) and NSFileHandle (FileHandle). I have an app that executes a child process (command line utility) and gets its output via Pipe instances set as standardI/O of Process instance. I can observe two logic flows: Once the child process exits, -[Process readabilityHandler] gets called where I gather the $0.availableData. Once the child process generates output (i.e. print() is executed by the child process), -[Process readabilityHandler] also gets called which makes sense. This is the case when exit() is not called by the child process (i.e. continuous execution). However, when LLDB is detached, #2 is false, i.e. -[Process readabilityHandler] is not called. Wrong behaviour also happens if I don't rely on readabilityHandler, but instead use Notification to receive changes in data availability. In such case, notification gets called continuously with empty data (even though child process does generate the output). If I don't create Pipe instance for standardI/O of the Process, then readabilityHandler does get called, but with an empty data continuously. I have created a DTS #756462540, since this doesn't make any sense. Prerequisites* app is not sandboxed Big Sur 11.0.1 (20B29) Xcode 12.3 (12C33)
Posted Last updated
.
Post marked as solved
8 Replies
468 Views
Hi! I wrote a backup console application. It does use ssh/sshfs to access a web server via public key. Also it does send an SMTP-mail when finished. If the process is started via launchctl load DAEMON it works always properly (RunAtLoad is true). But when the daemon is called automatically at night it does not always work. In my log I get these errors: ssh: connect to host SERVERURL port 22: Undefined error: 0 and Failed sending: NIOConnectionError(host: "mail.mydomain", port: 25, dnsAError: Optional(NIOCore.SocketAddressError.unknown(host: "mail.mydomain", port: 25)), dnsAAAAError: Optional(NIOCore.SocketAddressError.unknown(host: "mail.mydomain", port: 25)), connectionErrors: []) it does run on a MacMini M1 with macOS 12.2. Any clue what's wrong or how to find the reason of this issue? PS. On another MacMini (Intel) with macOS 11.6 the backup works since a year but there is always an admin user logged in.
Posted
by GreatOm.
Last updated
.
Post marked as solved
5 Replies
944 Views
We define an event handler for OpenURL NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; [appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; And we handle it here: (void)handleGetURLEvent:(NSAppleEventDescriptor *)event            withReplyEvent:(NSAppleEventDescriptor *)replyEvent { // Handler type stuff } If I'm debugging in Xcode, I see a SIGCONT before the handler is called. When I continue from the SIGCONT, I enter the handler and everything is fine. This causes automated tests to break, and is generally a pain in the you-know-where. Outside of Xcode it's fine. How can I make it stop doing this? Is there some Xcode setting I've overlooked?
Posted
by kjbrock.
Last updated
.
Post not yet marked as solved
8 Replies
596 Views
This question came from https://developer.apple.com/forums/thread/695826, where I saw crashes in AppKit if called without a GUI session. What troubles me from there is that our code is registered as a LaunchAgent (under /Library/LaunchAgents), and I was under the impression that a LaunchAgent only runs if a user logs into a GUI session. I tried at least ssh-only sessions and didn't see it launch automatically (I had to manually launch it through ssh to reproduce the crash). But the fact that we see thousands of crash reports coming from a few devices means somehow our LaunchAgent is trying to launch itself automatically &amp; repeatedly on these devices, while there is no GUI session so it keeps crashing. So, maybe there is a legit way to reproduce the scenario, to launch a LaunchAgent without a GUI session that I'm not aware of?
Posted
by qb_s.
Last updated
.
Post not yet marked as solved
2 Replies
428 Views
As per my research I found that there is no way to open general settings app but it is possible with openSettingsURLString. Can I use openURL API with options to open general settings? And also how can we request iOS API team to provide such support in future as this is so many time generated request.
Posted
by KPXlem.
Last updated
.