Created
March 20, 2018 15:11
-
-
Save bkth/849a765c616edfcd11132f8e4a455275 to your computer and use it in GitHub Desktop.
remote procedure call example in obj-c for macOS services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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