自定义iOS的应用程序:Cordova / Ionic项目中的didFinishLaunchingWithOptions:方法

我对Cordova很新,我想知道是否有办法调整Cordova / Ionic生成的平台代码,而不会妨碍开发过程.

具体要求是将Facebook SDK集成到iOS应用程序,以支持Facebook Mobile App Install广告.集成很简单:只需要​​添加一行代码即可
application:didFinishLaunchingWithOptions:在AppDelegate.m中并将Facebook iOS框架添加到Xcode项目中.

目前整个plaforms目录从源代码控制中排除,因为它是由Cordova在构建期间生成的.如果我要调整AppDelegate.m,我将不得不将它添加到源代码管理中.那么Ionic应用程序的后续更改是否会导致与Xcode项目的合并冲突?如何在不中断流程的情况下将我的小更改集成到Xcode项目中?

注意:我确实寻找一个插件作为解决方案,但我找到的插件是with complications of its own.而且看起来Cordova在应用程序中没有提供钩子:didFinishLaunchingWithOptions:无论如何.

解决方法

您应该创建自己的插件,而不是更改AppDelegate.m

你可以在pluginInitialize上听UIApplicationDidFinishLaunchingNotification,把代码放在那里

- (void)pluginInitialize
{

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];

}

- (void)finishLaunching:(NSNotification *)notification
{
    // Put here the code that should be on the AppDelegate.m
}

plugin.xml需要onload true才能调用pluginInitialize

<feature name="yourPluginName">
    <param name="ios-package" value="yourPluginClass" />
    <param name="onload" value="true" />
</feature>

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...