Clafou Clafou - 1 year ago 82
iOS Question

Customizing iOS's application:didFinishLaunchingWithOptions: method in a Cordova/Ionic project

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

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

Answer Source

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" />