Giter Site home page Giter Site logo

xuan32546 / mryipc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from muirey03/mryipc

0.0 0.0 0.0 253 KB

Easy-to-use iOS IPC without the need for RocketBootstrap

License: MIT License

Logos 2.56% Objective-C 10.60% Makefile 0.81% Shell 0.22% C 64.41% C++ 21.40%

mryipc's Introduction

MRYIPC

Easy-to-use iOS IPC without the need for RocketBootstrap

MRYIPC is an easy-to-use IPC (inter-process communication) mechanism for jailbroken devices (although it will also work on unjailbroken devices) that eliminates the need for RocketBootstrap.

MRYIPCCenter is similar in API to CPDistributedMessagingCenter, so it shouldn't be too challenging to replace current CPDistributedMessagingCenter implementations with MRYIPCCenter.

How to use

To use MRYIPC, copy MRYIPCCenter.h to $THEOS/include and usr/lib/libmryipc.dylib to $THEOS/lib. Then you can add XXX_LIBRARIES = mryipc to your Makefile and #import <MRYIPCCenter.h> into any source files you want to use it in. Then add Depends: com.muirey03.libmryipc to your control file.

An example usage can be seen in ExampleClient and ExampleServer in this repository.

The client

First, create the client center:

MRYIPCCenter* center = [MRYIPCCenter centerNamed:@"com.muirey03.MRYExampleServer"];

Then, go ahead and call any method you like:

NSNumber* result = [center callExternalMethod:@selector(addNumbers:) withArguments:@{@"value1" : @5, @"value2" : @7}];

MRYIPCCenter provides 3 ways to call methods on the center:

//asynchronously call a void method
-(void)callExternalVoidMethod:(SEL)method withArguments:(id)args;
//synchronously call a method and recieve the return value
-(id)callExternalMethod:(SEL)method withArguments:(id)args;
//asynchronously call a method and receive the return value in the completion handler
-(void)callExternalMethod:(SEL)method withArguments:(id)args completion:(void(^)(id))completionHandler;

Please note that the arguments and return value type must be one that can be stored in a plist (NSString*, NSNumber*, NSData*, NSArray* or NSDictionary*).

The server

IMPORTANT NOTE: Only one server is allowed for any given name. You cannot create 2 servers in 2 different processes with the same name, that is illegal, and will cause the second process to crash.

Again, start by creating a sever center with the same name as the client (you'll need to store a reference somewhere to stop it being deallocated):

MRYIPCCenter* center = [MRYIPCCenter centerNamed:@"com.muirey03.MRYExampleServer"];

Then register any methods you want to make external:

[center addTarget:self action:@selector(addNumbers:)];

Then just implement the methods and let MRYIPC handle the rest:

-(NSNumber*)addNumbers:(NSDictionary*)args
{
	NSInteger value1 = [args[@"value1"] integerValue];
	NSInteger value2 = [args[@"value2"] integerValue];
	return @(value1 + value2);
}

MRYIPC also allows for block-based servers for more simple callbacks where you don't necessarily need an object to act as the server:

static MRYIPCCenter* center;

%ctor
{
	center = [MRYIPCCenter centerNamed:@"com.muirey03.MRYExampleServer"];
	[center addTarget:^NSNumber*(NSDictionary* args){
		NSInteger value1 = [args[@"value1"] integerValue];
		NSInteger value2 = [args[@"value2"] integerValue];
		return @(value1 + value2);
	} forSelector:@selector(addNumbers:)];
}

Credits

Feel free to follow me on Twitter @Muirey03. If you have any contributions you want to make to this, please submit a Pull Request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.