I am trying to take control of the subject line in the Messages App. Right now I am just trying to display text in the Subject field.
The main issue I have is to get the compiler to recognize _subjectLine
as a valid view. This is what I get if I try and do anything to/with _subjectLine
:
Tweak.xm:8: error: ‘_subjectLine’ was not declared in this scope
I don't have any idea how to declare an already existing item to use in a tweak. The standard declarations that I use in Xcode, typically found in a header file, don't seem to work the same.
I've been googling around for about a week now. The most common tutorial or information I found was to do just simple: when method activates – display alert. I can do that, no problem. However, I need to use an already existing object.
It seems that in your case you are trying to use an instance variable of the class you are hooking. Modifying the instance variable does not work that way in tweaks. You have to use MSHookIvar to 'hook' an 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 hook stuff like BOOLs and floats etc.
exampleVariableHooked = MSHookIvar<BOOL>(self, "_someBOOL");
Its declared in substrate.h so you need to import that otherwise you will not be able to compile your tweak. Also as a bonus tip, I'm just reminding you that you have to put the identifier of the app/framework you're hooking in your tweakname.plist.
So after you 'hook' the variable you can change it to suit your needs. Happy coding!
You could also use the Objective-C runtime functions to access the instance variable, like so:
UIView *subjectLine;
object_getInstanceVariable(self, "_subjectLine", (void **)&subjectLine);
I'm not familiar with ChatKit, but took a quick peek. You can't access _subjectLine because it's an ivar. You should just access
id subject = [myCKContentEntryView subject]; // should return a CKTextContentView
NSAssert([subject isKindOfClass:[CKTextContentView class]], @"ack");
CKTextContentView * myTextContentView = subject;
The CKTextContentView has a setText method, but no idea what it's expecting since the parameter is id. Might be a view (UILabel?) or might take a string. You might try:
[myTextContentView setText:@"Hello World, w/ jimmies!"];
and see what happens.
You can use KVC. Example: [object valueForKey:@"whatever"];
It works anywhere, and is cleaner than using the Objective C runtime methods, or Mobile Substrate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With