导入ChatKit(即私有框架)或以某种方式使用CKDBMessage

问题描述 投票:2回答:2

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

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

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

我尝试的第一种方法是能够称之为:

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

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

  • 只需将CKDBMessage.h添加到我的项目中
  • 添加ChatKit.framework的所有标题
  • 添加ChatKit.framework文件本身

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

  • 框架搜索路径 - > $(PROJECT_DIR)/Headers
  • 标题搜索路径 - > $(SRCROOT)/Headers/ChatKit.framework/Headers $(SRCROOT)/Headers
  • 用户标题搜索路径 - > $(SRCROOT)/Headers $(SRCROOT)/Headers/ChatKit.framework/Headers

始终搜索用户路径始终为YES

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

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 performSelector:@selector(text)];

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

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

有关这两种方法的任何想法吗?

这是针对非越狱的iOS 8(.2),使用Xcode 6

ios objective-c iphone xcode6 iphone-privateapi
2个回答
4
投票

好吧没有多少人看过这个,但是为了我们的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来获取消息内容......


0
投票

目前,我正在使用XCode 10.这里我们可以在MessagesKit.framework路径中看到一个PrivateFrameworksMessagesKit.framework包含SOMessageHelper文件,我们可以在其中看到sendSMS函数。

功能:

(void)sendMessageText:(id)arg1 toRecipient:(id)arg2 withCompletionBlock:(CDUnknownBlockType)arg3;
© www.soinside.com 2019 - 2024. All rights reserved.