Skip to content

Instantly share code, notes, and snippets.

@bkth
Created March 20, 2018 15:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkth/849a765c616edfcd11132f8e4a455275 to your computer and use it in GitHub Desktop.
Save bkth/849a765c616edfcd11132f8e4a455275 to your computer and use it in GitHub Desktop.
remote procedure call example in obj-c for macOS services
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@protocol NetStorageXPCObjectHandler
- (void)lock;
- (void)unlock;
- (void)deleteAllResponses;
- (void)dealloc;
@end
int main(int argc, const char * argv[]) {
NSLog(@"Hello from process %d", [[NSProcessInfo processInfo] processIdentifier]);
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:@"com.apple.nsurlstorage-cache"];
connection.interruptionHandler = ^{
NSLog(@"Connection Terminated");
};
connection.invalidationHandler = ^{
NSLog(@"Connection invalidated");
};
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(NetStorageXPCObjectHandler)];
[connection resume];
[[connection remoteObjectProxy] dealloc];
[[connection remoteObjectProxy] deleteAllResponses];
[NSThread sleepForTimeInterval:1000.0f];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment