菜鸟教程小白 发表于 2022-12-11 16:48:56

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


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

<p>我已经找到了一些类似的问题,但还没有答案。
<a href="https://stackoverflow.com/questions/36792158/cordova-phonegap-ios-modify-generated-appdelegate" rel="noreferrer noopener nofollow">https://stackoverflow.com/questions/36792158/cordova-phonegap-ios-modify-generated-appdelegate</a> </p>

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

<p>有什么想法吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>也许您可以使用运行时在 AppDelegate.m 中添加新方法</p>

<pre><code>for example

@interface testViewController (){
    AppDelegate *m_appDelegate;
}

@implementation testViewController

- (void)viewDidLoad {
    ;

    m_appDelegate = ;

    // add new method in AppDelegate.m
    ;

    // call new method in AppDelegate.m
    ;


}

- (void)addMethod{

      BOOL addSuccess = class_addMethod(, @selector(join), (IMP)happyNewYear, &#34;v@:&#34;);

    }

    void happyNewYear(id self,SEL _cmd){
      NSLog(@&#34;new method&#34;);

    }

    -(void)join{
      NSLog(@&#34;in the join %s&#34;,__func__);
    }
</code></pre>

<p>希望对你有帮助。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios -CordovaiOS : Add method call in AppDelegate. m,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37984851/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37984851/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Cordova iOS : Add method call in AppDelegate. m