今天一朋友发邮件咨询我一个MobileNotes实例的问题:

说按照 沙梓社先生的《iOS应用逆向工程》第二版 第七章 进行实验,发现标题不会即时进行更新(试验环境为iOS8.4+iPhone4s)


由于我没有这本书,刚好看到一个样章:

http://www.doc88.com/p-6992150739940.html

样章用的8.1.x,我没有这个版本的,因此同样找了台4s 8.4的系统进行测试


我大致浏览了一遍,然后写个tewak给提出问题的朋友试验了下~ 

self.note.contentAsPlainText; // 发现这句得到的是更新前(也就是未点击“Done”按钮前)的内容

 遂修改如下:

@interface NoteObject : NSObject
@property(readonly, nonatomic) NSString *contentAsPlainText;
// Added By PiaoYun/P.Y.G
@property(readonly, nonatomic) NSString *title;
@end

@interface NoteTextView : UIView
@property(copy, nonatomic) NSString *text;
@end

@interface NoteContentLayer : UIView
@property(retain, nonatomic) NoteTextView *textView;
@end

@interface NotesDisplayController : UIViewController
@property(retain, nonatomic) NoteContentLayer *contentLayer;
@property(retain, nonatomic) NoteObject *note;

- (void)setTitle;
@end

%hook NotesDisplayController

%new 
- (void)setTitle{
	/**
	Modify By PiaoYun/P.Y.G
	www.chinapyg.com
	www.dllhook.com
	**/
	NSString *nsContent = [[self note] title]; // self.note.contentAsPlainText;
	NSString *nsContentLen = [NSString stringWithFormat:@"%lu", (unsigned long)[nsContent length]];
	self.title = nsContentLen;
}

- (void)viewWillAppear:(BOOL)view{
	%orig;
	[self setTitle];
}

- (void)viewWillDisappear:(BOOL)view{
	%orig;
	self.title = nil;
}

- (void)noteContentLayerContentDidChange:(NoteContentLayer *)noteContentLayerContent updatedTitle:(BOOL)title{
	%orig;
	[self setTitle];
}
%end


你可能感兴趣的文章

评论区

已有1位网友发表了看法:

1L snakeninny  2015-10-05 22:07:28 回复
感谢飘云兄对书上示例在新版系统中的改进!

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。