Apple Push Notification Service native extension for Adobe AIR

Here’s another AIR native extension for iOS I’m currently working on – Apple Push Notification Service (APNs) support.
It’s almost complete – the most important things are there. You can register to APNs, get your device token and receive remote notification in ActionScript – everything that you need to build a great app.

Grab the source from github: https://github.com/pkoscierzynski/NativeAPNService

To run the example you need to go to Apple Developer Portal and create a new application id, generate push notification certificates and a new mobile provisioning profile.
I’d recomend this tutorial by Matthijs Hollemans, it’s very detailed and self explanatory (like all the tutorials on Ray’s site).
Apple Push Notification Services Tutorial: Part 1/2

I also used php sample to publish my message to APNs sandbox servers. Follow the tutorial step by step and you should get everything working.

When you’ll have your app id and be sure to put it in the apropriate xml tags of AIR application descriptior.
In AIR 3.1, application descriptor has a new section for iOS apps – Entitlements. In Entitlements section you need to provide the id of you application, otherwise the APN won’t work (this section is the content of Entitlements.plist file known from native Xcode / Objective-C).

Adobe AIR application descriptor. iPhone Entitlements section.

Apple Push Notifications in Adobe AIR iOS application from Piotr Koscierzynski on Vimeo.

No related posts.

48 thoughts on “Apple Push Notification Service native extension for Adobe AIR

  1. Should this work with AIR 3.0? I am getting a Exception in thread “main” java.lang.Error: Unable to find named traits: pl.randori.air.nativeextensions.ios::APNSExtension

    Using ADT to package. My reference to the ANE file in flash is set to external as it should be. Contact me at my email address, I could use your help on this and we can pay you for your time.

    Thanks!

    Mike

      • I got it working, I wasn’t specifying the extension ID in my app config file. Is there a way to turn off the dialogs that appear displaying the device id? I need to get this working today. Please contact me. Thanks!

        Mike

      • I’m interested too by this source code. I success to compile your version but I need to get the first push, when application is not launched and waked by the notification.
        In your app, the push is received by the extension, but not transmitted to the app (because it’s not initialized yet).
        I think to “save” it into extension, wait for the dispatching of application complete and then, re send an event to get this message.
        Sorry for my English maybe so bad :-s and thanks a lot for this great example.

  2. Hi, once again love Your work.
    I got just one question. Is it posible You would add a support for Windows or a mac. It can return gibberish but with the function isSupported .. please!!
    I can’t imagine anybody debbuging a whole app just on ios.. And as You know in flash builder simulator we got this lovely error: “incompatible with this environment”.
    pretty please:)

  3. Hi.

    I’m trying you ane but when i try to compile, I get an error:

    “Id: file not found: %ADT_ENV_VAR_26%”
    “Compilation failed while executing: Id64″

    I’m using windows 7

    Can you help?

    Thanks

      • Do u mean that i shall make .m file implement UIApplicationDelegate and define the method:
        -(void) application :( UIApplication *) application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken

        ?Then change the default delegate of UIApplication?

  4. Will you be releasing the source code? Or a commercial version of the extension?

    I got everything to work ok which is great but now I want to use the extension in a proper project so I don’t want the alert which comes up and ideally the event type would be more specific – currently the type of APNSExtensionEvent does not indicate a specific type e.g. token.

    Any help?

    • As far as I know it’s not possible to codesign (+Entitlements.plist) an IPA archive on Windows. You need iOS SDK tools which is only available on MacOS X.
      I don’t have a Windows so I haven’t really tried to make it work.

  5. Hi Piotr Koscierzynski, thanks for all! now i’ve compiled your example app in my os workstation.. and it works!!! Thanks a lot.

    But , for testing pushing from my server, i need know the device token, how i can get it? you write about a Status Event: how can i access this property?

    Thanks and have a nice day.

  6. under the view1_creationCompleteHandler(event:FlexEvent),

    apnServiceExtension = new APNSExtension();
    apnServiceExtension.addEventListener(APNSExtensionEvent.APN_SERVICE_EVENT, onRemoteNotificationEvent);

    I did not received any return token or any message, the textarea just show nothing Anyone had this problem?

    • You didn’t receive any notifation because the device failed to register to APNs servers. That’s a very common error – check your provisioning profile, app ID, etc.

      • Hi Piotr,
        I’m trying and trying again, but I’m missing something …
        In my case, textarea shows:
        ” will send request to APNS (the first row)
        Registering device to APNS (the second row)”
        and at same time, native popup shows “AIR APN EVENT”( as title) “Registering to APNS” (popop body).. and no more (no token etc..) and that every time I click on “Register To APN Service” button..

        What am I doing wrong? I’m trying on a iPad (1)
        thank you so much

  7. Hey,

    Was wondering how you assigned the delegate class in your code, been trying to do this myself, but keep running into problems as soon as I set

    [UIApplication sharedApplication].delegate

    It seems that as soon as I set that all the other FRE functions to communicate back to flash stop working.

    Any help is appreciated, cheers!

  8. Hello,

    i successfuly compile my ipa, APNSExtension is available (i can trace it).
    But once i instantiate:
    apnServiceExtension = new APNSExtension();

    my app crash instantly….

    any idea ??

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> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">