How to add event handlers to the AppDelegate in Objective-C

When you are working on a Native Extension for iOS, as a rule, you don’t have direct access to your app’s AppDelegate class, which is how you control UIApplication.

Suppose you want to intercept events in your app either before they get to the ActionScrip (AIR) side or because they won’t get there in the first place. This tutorial will show you how to do it.

Replace AppDelegate’s didReceiveRemoteNotification method

We will do this in a function, called registerApplicationEventHandlers() which you implement in your native code. The idea here is that you get access to the AppDelegate that AIR created and trick it into accepting your implementation of one or more of its methods.

Now implement replaceMethodImplementation(), which registerApplicationEventHandlers() calls.

Provide your custom implementation

Here you implement your own didReceiveRemoteNotification method that will be called instead of the default one.

Make sure the replacement method is called

When do you call registerApplicationEventHandlers()? Preferably before any of the methods you replace in it should be called, but after your AppDelegate has been created. In the context of an ANE the best place for that is in your extension context initializer:

Info: For a data conversion guide between ActionScript and Objective-C download our eBook “iOS vs. ActionScript Data Types Guide”.

 


Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Comments

  1. Johan Degraeve

    the didReceiveRemoteNotification implementation sample seems to have wrong code. It’s a copy/paste of the replacemethodimplementation.

    Could you update the sample ?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">