我正在为 iOS 使用 cordova/ionic 构建一个应用程序 由于多种原因,我们必须将代码放入 AppDelegate.m 生成的 application() 中。
我已经找到了一些类似的问题,但还没有答案。 https://stackoverflow.com/questions/36792158/cordova-phonegap-ios-modify-generated-appdelegate
有一种方法可以通过一些重载或扩展来正确地做到这一点吗? 简单的答案是“我可以编辑 AppDelegate.m”,但由于它是项目中生成的文件,我不能这样做。
有什么想法吗?
最佳答案
也许您可以使用运行时在 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__);
}
希望对您有所帮助。
关于ios - Cordova iOS : Add method call in AppDelegate. m,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37984851/