Theos: Trying to take UIView _subjectLine from CKContentEntryView in ChatKit

I'm trying to take control of a subject line in the Messages application. Now I'm just trying to display the text in the Subject field.

The main problem is forcing the compiler to be recognized _subjectLineas a valid representation. This is what I get if I try to do something in / s _subjectLine:

Tweak.xm:8: error: ‘_subjectLine’ was not declared in this scope

I do not know how to declare an existing item for use in customization. The standard declarations that I use in Xcode, as a rule, are found in the header file, and they do not seem to work the same.

I’ve been going for a walk for about a week. The most common textbook or information that I found should have been done simply: when the method is activated, display a warning. I can do it, no problem. However, I need to use an existing object.

+5
source share
4 answers

It seems that in your case you are trying to use an instance variable the class you are connecting. Changing an instance variable does not work this way in settings. You must use MSHookIvar to "intercept" the instance variable (aka ivar). Example:

[Tweak.xm / mm]

#import <substrate.h> // necessary
#import <Foundation/Foundation.h>

@interface TheClassYouAreHooking : NSObject {
    NSString *_exampleVariable;
}
- (void)doSomething;
@end

NSString *_exampleVariableHooked;

%hook TheClassYouAreHooking
- (void)doSomething 
{
    // 'Hook' the variable

    exampleVariableHooked = MSHookIvar<NSString *>(self, "_exampleVariable");

    // The name of the hooked variable does not need to be the same

    exampleVariableHooked = @"Hello World";

    // You can do ANYTHING with the object Eg. [exampleVariableHooked release];

}
%end

MSHookIvar can also connect things like BOOL and float, etc.

exampleVariableHooked = MSHookIvar<BOOL>(self, "_someBOOL");

.h, , . , , , /, tweakname.plist.

, , , . !

+8

Objective-C , :

UIView *subjectLine;
object_getInstanceVariable(self, "_subjectLine", (void **)&subjectLine);
+2

ChatKit, . _subjectLine, ivar.

id subject = [myCKContentEntryView subject]; // should return a CKTextContentView
NSAssert([subject isKindOfClass:[CKTextContentView class]], @"ack");
CKTextContentView * myTextContentView = subject;

CKTextContentView setText, , , id. (UILabel?) . :

[myTextContentView setText:@"Hello World, w/ jimmies!"];

, .

+1
source

You can use KVC. Example: [object valueForKey: @ "whatever"];

It works anywhere and is cleaner than using Objective-C runtime methods or a mobile substrate.

+1
source

All Articles