在Cordova / Ionic项目中定制iOS的应用程序:didFinishLaunchingWithOptions:方法 [英] Customizing iOS's application:didFinishLaunchingWithOptions: method in a Cordova/Ionic project

查看:647
本文介绍了在Cordova / Ionic项目中定制iOS的应用程序:didFinishLaunchingWithOptions:方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Cordova的新手,我想知道是否有办法调整Cordova / Ionic生成的平台代码,而不会影响开发过程。



要求是将Facebook SDK集成到iOS应用程序,以支持Facebook移动应用安装广告。集成很简单:它只需要在AppDelegate.m中向
应用程序:didFinishLaunchingWithOptions:添加一行代码,并将Facebook iOS框架添加到Xcode项目。 / p>

目前,整个plaforms目录从源代码控制中排除,因为它是在构建期间由Cordova生成的。如果我要调整AppDelegate.m,我必须将它添加到源代码控制。然后不会对Ionic应用程序的后续更改导致与Xcode项目的合并冲突?



注意:我找到了一个插件作为解决方案,但我发现的插件来自其自身的复杂性。看起来Cordova在应用程序中不提供钩子:didFinishLaunchingWithOptions:


解决方案

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



您可以通过 UIApplicationDidFinishLaunchingNotification pluginInitialize 上放置代码

   - )pluginInitialize 
{

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

}

- (void)finishLaunching:(NSNotification *)notification
{
//在这里放置应该在AppDelegate上的代码。 m
}

plugin.xml需要onload true来调用pluginInitialize

 < feature name =yourPluginName> 
< param name =ios-packagevalue =yourPluginClass/>
< param name =onloadvalue =true/>
< / feature>


I'm newish to Cordova and am wondering if there is a way to tweak the platform code generated by Cordova/Ionic without hindering the development process.

The specific requirement is to integrate the Facebook SDK to the iOS app in order to support Facebook Mobile App Install ads. Integration is straightforward: it only requires adding a line of code to application:didFinishLaunchingWithOptions: in AppDelegate.m and adding the Facebook iOS framework to the Xcode project.

Currently the entire plaforms directory is excluded from source control, as it is generated by Cordova during build. If I am to tweak AppDelegate.m, I will have to add it to source control. Then won't subsequent changes to the Ionic app result in merge conflicts with the Xcode project? How can I integrate my small changes to the Xcode project without breaking the process?

NOTE: I did look for a plugin as a solution, but the plugin I found comes with complications of its own. And it appears that Cordova does not provide hooks in application:didFinishLaunchingWithOptions: anyway.

解决方案

You should create your own plugin instead of making changes into the AppDelegate.m

You can listen the UIApplicationDidFinishLaunchingNotification on the pluginInitialize an put the code there

- (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
}

The plugin.xml need the onload true to call the pluginInitialize

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

这篇关于在Cordova / Ionic项目中定制iOS的应用程序:didFinishLaunchingWithOptions:方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆