OGeek|极客世界-中国程序员成长平台

标题: ios - 导入 ChatKit(即私有(private)框架)或以某种方式使用 CKDBMessage [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:26
标题: ios - 导入 ChatKit(即私有(private)框架)或以某种方式使用 CKDBMessage

首先 - 我知道私有(private)框架/API 不会让我进入 AppStore,这仅供私有(private)使用/研究。

我无法使用 ChatKit.framework 编译我的项目。

基本上我需要以某种方式初始化一个 CKDBMessage 对象并从中获取内容。

我尝试的 first 方法是能够调用它:

    CKDBMessage* msg = [[CKDBMessage alloc] initWithRecordID:lastID];
    NSLog(@"GOT SMS: %@", msg.text);

我无法使用这些解决方案的任何组合对其进行编译:

我在 Headers 文件夹中有标题和框架文件,我尝试在递归/非递归上添加任何/所有这些build设置:

始终搜索用户路径始终为"is"

我尝试的第二件事是在运行时做所有事情,这就是我所拥有的:

Class CKDBMessage = NSClassFromString(@"CKDBMessage");// objc_getClass("CKDBMessage");

SEL sel = @selector(initWithRecordID;

NSMethodSignature *signature = [CKDBMessage methodSignatureForSelector:sel];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.selector = sel;
[invocation setArgument:&lastID atIndex:2];
[invocation invoke];

NSObject * msgWeak = [CKDBMessage alloc];
[invocation getReturnValue:&msgWeak];
NSObject *msg = msgWeak;

NSString *text = [msg performSelectorselector(text)];

NSLog(@"text: %@", text);

这里我在 invocationWithMethodSignature: 处崩溃,因为 NSClassFromString 返回 nil 而不是类...

对这两种方法有什么想法吗?

这是未越狱的,iOS8(.2),使用 Xcode6



Best Answer-推荐答案


好吧,没有多少人看过这个,但是为了我们的 wiki 社区,我设法通过将 CKDBMessage.h 文件添加到我的项目中来解决这个问题(实际上我添加了 ChatKit 但我认为没有必要),而不是像这样使用 dlopen 动态加载框架:

dlopen("/System/Library/PrivateFrameworks/ChatKit.framework/ChatKit", RTLD_LAZY)

所以我的完整解决方案是:

dlopen("/System/Library/PrivateFrameworks/ChatKit.framework/ChatKit", RTLD_LAZY);

Class CKDBMessageClass = NSClassFromString(@"CKDBMessage");
CKDBMessage *msg = [[CKDBMessageClass alloc] initWithRecordID:lastID];

NSString *text = msg.text;
NSLog(@"text: %@", text);

获取最后一条消息的ID涉及到另一个框架:IMDPersistence:

//SomeFile.h
// ...
//declare the function:
static int (*IMDMessageRecordGetMessagesSequenceNumber)();

// SomeFile.m
// ...
//open IMDPersistence framework
void *libHandleIMD = dlopen("/System/Library/PrivateFrameworks/IMDPersistence.framework/IMDPersistence", RTLD_LAZY);

//make/get symbol from framework + name
IMDMessageRecordGetMessagesSequenceNumber = (int (*)())dlsym(libHandleIMD, "IMDMessageRecordGetMessagesSequenceNumber");

// get id of last SMS from symbol
int lastID = IMDMessageRecordGetMessagesSequenceNumber();

现在您可以使用 lastID 来获取消息内容...

关于ios - 导入 ChatKit(即私有(private)框架)或以某种方式使用 CKDBMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29151710/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4