Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LeoNatan/LNIPCConnection
An asynchronous, bidirectional inter-process remote invocation framework for Apple platforms, with an API similar to Apple's NSXPCConnection.
https://github.com/LeoNatan/LNIPCConnection
Last synced: 3 months ago
JSON representation
An asynchronous, bidirectional inter-process remote invocation framework for Apple platforms, with an API similar to Apple's NSXPCConnection.
- Host: GitHub
- URL: https://github.com/LeoNatan/LNIPCConnection
- Owner: LeoNatan
- License: mit
- Created: 2021-02-15T20:28:08.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T08:54:07.000Z (almost 2 years ago)
- Last Synced: 2024-07-18T05:37:09.432Z (4 months ago)
- Language: Objective-C
- Homepage:
- Size: 81.1 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LNIPCConnection
`LNIPCConnection` is an asynchronous, bidirectional inter-process remote invocation framework for Apple platforms, with an API similar to Apple's `NSXPCConnection`.
Once a connection is established, messages sent to remote proxies are serialized over mach ports to their remote counterparts. Block parameters are supported, and their lifetime is mirrored to their remote proxy counterparts (if a proxy block is retained and remains active for use, so is the local proxy).
**Note:** This framework is intended primarily for testing purposes, such as between a test runner process and the tested app process. The framework uses private API and is not suitable for App Store submission. On macOS, use an XPC service. On iOS and tvOS, due to the limited viability of multiple processes running at the same time, the framework is less useful there anyway.
## Usage
Include the project in your projects and link it.
Read the `LNIPCConnection.h` header for full documentation.
First, create a common protocol, which will be used to define the interface between remote objects.
```objc
@protocol ExampleProtocol- (void)performOperationWithCompletionHandler:(dispatch_block_t)block;
- (void)performOperationWithOptions:(NSDictionary*)options completionHandler:(NSDictionary* options)block;@end
```On the server process, create a class which implements the common protocol you have defined. Create an `LNIPCConnection` object with a named service, set an exported interface and set the exported object. Optionally, you can also set the remote object interface for bi-directional communication.
```objc
@interface MyObject : NSObject @end
@implementation MyObject
- (void)performOperationWithCompletionHandler:(dispatch_block_t)block
{
NSLog(@"Called performOperationWithCompletionHandler:");
block();
}- (void)performOperationWithOptions:(NSDictionary*)options completionHandler:(NSDictionary* options)block
{
NSLog(@"Called performOperationWithOptions:completionHandler: with options: %@", options);
block(options);
}@end
//…
_connection = [[LNIPCConnection alloc] initWithServiceName:@"MyService"];
_connection.exportedInterface = [LNIPCInterface interfaceWithProtocol:@protocol(ExampleProtocol)];
_connection.exportedObject = [[MyObject alloc] init];[_connection resume];
```On the client process, connect to the registered named service, set the remote object interface and obtain a remote proxy object. You can now use this proxy object as if it is an instance of the remote object.
```objc
_connection = [[LNIPCConnection alloc] initWithServiceName:@"MyService"];
_connection.remoteObjectInterface = [LNIPCInterface interfaceWithProtocol:@protocol(ExampleProtocol)];[_connection resume];
id remoteProxyObject = _connection.remoteObjectProxy;
[remoteProxyObject performOperationWithCompletionHandler:^ {
NSLog("Completion handler called");
}];[remoteProxyObject performOperationWithOptions:@{@"Test": @"Passed"} completionHandler:^ (NSDictionary* options) {
NSLog("Completion handler called with options: %@", options);
}];
```The expected output on the server process should be:
```
Called performOperationWithCompletionHandler:
Called performOperationWithOptions:completionHandler: with options: {
Test = Passed;
}
```And the client process:
```
Completion handler called
Completion handler called with options: {
Test = Passed;
}
```#### Acknowledgements
Originally developed by me for Wix.