【问题标题】:Cordova iOS : Add method call in AppDelegate.mCordova iOS:在 AppDelegate.m 中添加方法调用
【发布时间】:2016-06-23 07:25:07
【问题描述】:

我正在为 iOS 构建一个带有 cordova/ionic 的应用程序 由于多种原因,我们必须将代码放在 AppDelegate.m 的生成 application() 中。

我已经找到了一些类似的问题,但还没有答案。 https://stackoverflow.com/questions/36792158/cordova-phonegap-ios-modify-generated-appdelegate

有没有办法通过一些重载或扩展来正确地做到这一点? 简单的答案是“我可以编辑 AppDelegate.m”,但由于它是项目中生成的文件,我不能这样做。

有什么想法吗?

【问题讨论】:

    标签: 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__);
        }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 2015-08-22
      • 2016-01-13
      • 2020-07-31
      • 2020-04-27
      • 1970-01-01
      相关资源
      最近更新 更多