Search code examples
ioscordovaconfigphonegap-plugins

Phonegap Plugin - append lines to app delegate


I'm developing a phonegap plugin. So far so good. Now I would like to append 1 or 2 methods to the AppDelegate.m through the config.xml so it will be populated for the developer automatically. Is it possible?

Thanks.


Solution

  • take a look into the Push Plugin, they use an objective-c category for the appDelegate

    https://github.com/phonegap-build/PushPlugin

    If you just want to be notified when the app becomes active you don't need to change anything on the AppDelegate, just put this on your plugin:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; 
    
    - (void)onAppDidBecomeActive:(NSNotification*)notification
    {
    
         NSLog(@"%@",@"applicationDidBecomeActive");
    
    }