Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 927
Clafou Avatar asked Jun 23 '15 10:06

Clafou


2 Answers

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>
like image 61
jcesarmobile Avatar answered Sep 24 '22 17:09

jcesarmobile


You could use this plugin for that: https://github.com/katzer/cordova-plugin-app-event

like image 27
IonicBurger Avatar answered Sep 22 '22 17:09

IonicBurger