Phonegap Plugin - append lines to app delegate

末鹿安然 提交于 2019-12-08 19:16:48

问题


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.


回答1:


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");

}



回答2:


If you do need to override some other method, like if iOS doesn't issue a notification for some app delegate method, you can do it with method swizzling. jcesarmobile mentioned this repo in his answer, but a file with an example is:

https://github.com/phonegap-build/PushPlugin/blob/master/src/ios/AppDelegate%2Bnotification.m



来源:https://stackoverflow.com/questions/21490212/phonegap-plugin-append-lines-to-app-delegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!