【问题标题】:Cordova iOS : Add method call in AppDelegate.mCordova iOS:在 AppDelegate.m 中添加方法调用
【发布时间】:2016-06-23 07:25:07
【问题描述】:
【问题讨论】:
标签:
ios
objective-c
iphone
cordova
appdelegate
【解决方案1】:
也许您可以使用运行时在 AppDelegate.m 中添加新方法
for example
@interface testViewController (){
AppDelegate *m_appDelegate;
}
@implementation testViewController
- (void)viewDidLoad {
[super viewDidLoad];
m_appDelegate = [AppDelegate new];
// add new method in AppDelegate.m
[self addMethod];
// call new method in AppDelegate.m
[m_appDelegate performSelector:@selector(join)];
}
- (void)addMethod{
BOOL addSuccess = class_addMethod([AppDelegate class], @selector(join), (IMP)happyNewYear, "v@:");
}
void happyNewYear(id self,SEL _cmd){
NSLog(@"new method");
}
-(void)join{
NSLog(@"in the join %s",__func__);
}
希望对你有帮助。