Import ChatKit (i.e., Private Framework) OR using CKDBMessage somehow

二次信任 提交于 2019-12-06 05:20:41

Well not many people viewed this, but for the sake of our wiki community, I managed to solve this by adding the CKDBMessage.h file to my project (actually I added all the headers of ChatKit but I don't think it's necessary), than I loaded the framework dynamically with dlopen like so:

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

So my full solution is:

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);

Getting the ID of the last message involves another framework: 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();

Now you can use lastID to get the message contents...

Hitesh Borse

Currently, I am using XCode 10. here we can see one MessagesKit.framework in PrivateFrameworks path. MessagesKit.framework contains SOMessageHelper file where we can see sendSMS function.

Function :

(void)sendMessageText:(id)arg1 toRecipient:(id)arg2 withCompletionBlock:(CDUnknownBlockType)arg3;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!