章节尾部编写Tweak部分,按照书中步骤生成一个Tweak,如下:
CharacountForNotes8.h
@interface NoteObject : NSObject
@property (readonly, nonatomic) NSString *contentAsPlainText;
@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;
@end
Tweak.tw
#import "CharacountForNotes8.h"
%hook NotesDisplayController
- (void)viewWillAppear:(BOOL)arg1 // Initialize title
{
NSLog(@"Hello");
}
- (void)viewDidDisappear:(BOOL)arg1 // Reset title
{
NSLog(@"Hello");
}
- (void)noteContentLayerContentDidChange:(NoteContentLayer *)arg1 updatedTitle:(BOOL)arg2 // Update title
{
NSLog(@"Hello");
}
%end
然后make package install,报错如下:
Tweak.xm:4:597: error: unknown type name 'NoteContentLayer'
…SEL, NoteContentLayer *, BOOL); static void _logos_method$_ungrouped$Not…
^
Tweak.xm:4:761: error: unknown type name 'NoteContentLayer'
…SEL, NoteContentLayer *, BOOL);
^
Tweak.xm:17:699: error: address of overloaded function
'_logos_method$_ungrouped$NotesDisplayController$noteContentLayerContentDidChange$updatedTitle$'
does not match required type 'id (id, SEL *, …)'
…_logos_method$_ungrouped$NotesDisplayController$noteContentLayerContentDidChange$updatedTitle$…
我的环境是iphone5c, ios8.2,求大神帮忙指点一下,谢谢!
xiongzhend:
error: unknown type name
应该是循环引用报的错,但这里并没有循环引用啊?你把
xiongzhend:
(void)noteContentLayerContentDidChange:(NoteContentLayer *)arg1 updatedTitle:(BOOL)arg2 // Update title
{
NSLog(@“Hello”);
}
注释掉再编译试试
去掉这一个函数就编译通过了,但这是什么问题呢,去掉就没意义了不是么?
另外,我在做下一个例子,MobileMail这个的时候,同样的unknown type name ‘NSConcreteNotification’
我都懞了,这是魔咒么
你把CharacountForNotes8工程打个包传上来我看看
我把
#import "CharacountForNotes8.h"
%hook NotesDisplayController
- (void)viewWillAppear:(BOOL)arg1 // Initialize title
{
NSLog(@"Hello");
}
- (void)viewDidDisappear:(BOOL)arg1 // Reset title
{
NSLog(@"Hello");
}
- (void)noteContentLayerContentDidChange:(NoteContentLayer *)arg1 updatedTitle:(BOOL)arg2
{
NSLog(@"Hello");
}
%end
改成
#import "CharacountForNotes8.h"
%hook NotesDisplayController
- (void)viewWillAppear:(BOOL)arg1 // Initialize title
{
NSLog(@"Hello");
}
- (void)viewDidDisappear:(BOOL)arg1 // Reset title
{
NSLog(@"Hello");
}
- (void)noteContentLayerContentDidChange:(NoteContentLayer *)arg1 updatedTitle:(BOOL)arg2
{
NSLog(@"Hello");
}
%end
就可以编译通过了。
貌似是Theos的bug?我确认一下,如果确实是,就给DHowett反馈一下
在我的其他工程中没有出现这个问题,你留意一下这个问题出现的规律,总结一下发出来看看其他人能否重现
嗯,狗神确实是这样,好像就是一行空格的问题,谢谢。大家有遇到类似情况的可以试试空上一行这个方法!
我一行行按照书上敲代码,但是偏偏#import的那行会有红色下划线,然后编译可以通过,但是就是不会hook到相关代码,如果直接把你的这段代码复制过来,确实可以在syslog里看到相关Log
那肯定是你的代码哪里打错了呗,你可以用BeyondCompare对比一下,比肉眼看强
我也是找了半天这个问题,看了狗神的回复,才好使~非常感谢
挖坟了。请问你们所自定义的Header File 「CharacountForNotes8.h」放到Tweak工程的哪个目录下啊?
总不会老是放在/opt/theos/include/这个目录下吧?自定义的东西,总感觉theos应该有规范它放的地方吧。
我翻了一下theos源码,发现在可以在Makefile里这样来追加 :
THEOS_INCLUDE_PATH := include/
这样相当于在工程目录新建一个include/
目录,把自定义的头文件扔进这里放着就好了。没验证过,有心人验证一下。
1 个赞
Zhang
2017 年5 月 3 日 09:35
16
其实一般同目录然后 #include "qwewqewqeqwe.H"
就好了。。。。