Libobjcipc: Difference between revisions

From iPhone Development Wiki
m (Updated to latest version)
(→‎Example Projects: 1 more tweak.)
Line 65: Line 65:
| [https://github.com/a1anyip/Google-Authenticator-for-ProWidgets/tree/master/AuthenticatorSubstrate Subproject in Google Authenticator for ProWidgets]
| [https://github.com/a1anyip/Google-Authenticator-for-ProWidgets/tree/master/AuthenticatorSubstrate Subproject in Google Authenticator for ProWidgets]
| [https://github.com/a1anyip Alan Yip]
| [https://github.com/a1anyip Alan Yip]
|-
| [https://github.com/PoomSmart/KBMoreMem KBMoreMem]
| [https://github.com/PoomSmart PoomSmart]
|}
|}



Revision as of 08:23, 24 May 2016

Libobjcipc
Cydia Package
Developer Alan Yip
Package ID cc.tweak.libobjcipc
Latest Version 1.0.1


libobjcipc is a developer library that provides an inter-process communication (between app and SpringBoard) solution for jailbroken iOS. It handles the socket connections between SpringBoard and app processes, the automatic set up of process assertions and the auto disconnection after timeout or the process terminates.

You only need to call the static methods in the main class OBJCIPC. Messages and replies can be sent synchronously (blocking) or asynchronously.

How to use this library

Headers are available from libobjcipc GitHub project and the library can be found at /usr/lib/libobjcipc.dylib on a device where libobjcipc is installed. If using Theos, place the headers in $THEOS/include/objcipc, the library in $THEOS/lib/ and add objcipc to the XXX_LIBRARIES Makefile variable.

Basic Usage

The basic usage of the library is to have an extra MobileSubstrate extension which hooks into a specific app to set up an incoming message handler. Another instance in SpringBoard process sends a message to that app and wait for its reply, and vice versa. Messages can be sent from either end.

The library ensures that the receiver is able to receive new messages so it will make the app process stay in background until timeout occurs. Some potential problems, for instance the app is not opened yet or crashes, are appropriately handled by the library itself. In such cases, the messages are sent once the app process is opened or the sender gets an instant empty reply if there is any problem in the receiver (e.g. the app crashes).

If you encounter any crashes in the receiver end, check whether the incoming message handler (block) in the receiver end causes any crashes.

Send message

// Asynchronous message sent from SpringBoard to app (MobileTimer in this case)
[OBJCIPC sendMessageToAppWithIdentifier:@"com.apple.mobiletimer" messageName:@"Custom.Message.Name" dictionary:@{ @"key": @"value" } replyHandler:^(NSDictionary *response) {
    NSLog(@"Received reply from MobileTimer: %@", response);
}];

// Asynchronous message sent from app to SpringBoard
[OBJCIPC sendMessageToSpringBoardWithMessageName:@"Custom.Message.Name" dictionary:@{ @"key": @"value" } replyHandler:^(NSDictionary *response) {
    NSLog(@"Received reply from SpringBoard: %@", response);
}];

// Synchronous message sent from app to SpringBoard
NSDictionary *reply = [OBJCIPC sendMessageToSpringBoardWithMessageName:@"Custom.Message.Name" dictionary:@{ @"key": @"value" }];

Handle incoming messages

// Handle messages sent from any app in SpringBoard
[OBJCIPC registerIncomingMessageFromAppHandlerForMessageName:@"Custom.Message.Name"  handler:^NSDictionary *(NSDictionary *message) {
    // return something as reply
    return nil;
}];

// Handle messages sent from the specific app in SpringBoard
[OBJCIPC registerIncomingMessageHandlerForAppWithIdentifier:@"com.apple.mobiletimer" andMessageName:@"Custom.Message.Name" handler:^NSDictionary *(NSDictionary *message) {
    // return something as reply
    return nil;
}];

// Handle messages sent from SpringBoard in app
[OBJCIPC registerIncomingMessageFromSpringBoardHandlerForMessageName:@"Custom.Message.Name" handler:^NSDictionary *(NSDictionary *message) {
    // return something as reply
    return nil;
}];

Example Projects

Project Author
Subproject in Google Authenticator for ProWidgets Alan Yip
KBMoreMem PoomSmart

External links