ios - Cordova iOS : Add method call in AppDelegate. m

标签 ios objective-c iphone cordova appdelegate

我正在为 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/

相关文章:

ios - 自定义 TableViewController tableView() 方法未调用

html - ios8 Webview svg 嵌入 html 不显示

iphone - 从 View 中显示新 View 然后在 iphone 中返回到它的正确方法是什么

iphone - UIToolbar 的多个类别

iphone - 检查用户是否在其 iDevice 上设置了电子邮件?

ios - iTunes 连接 : In App Purchases - Developer Action Needed

ios - 无法满足 UILabel 对动态 UITableViewCell 的 ContentView 的底部约束

ios - UIScrollview - 屏幕外按钮不触发

iphone - 如果不在 iphone 应用程序中向下滚动,Scrollview 不会显示其内容的顶部

ios - 从 zip 文件无法从文档目录中获取数据