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).
Apple Push Notifications in Adobe AIR iOS application from Piotr Koscierzynski on Vimeo.
No related posts.




i try it and for me work perfectly..
thanks. you are congratulations for shared this arthicle
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
This version won’t work with AIR 3.0. But it’s possible to compile a AIR 3.0 compatible version.
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
Hi Piotr,
I would like to know, if your objective c source code can be available to me.
Thanks..
I will release the code in the future.
I only need the listener method that receives the device token.
you can help me?
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.
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:)
I’ll check this issue when I get access to a PC with Windows. But can’t promise you when that would be.
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
I have no idea what might be the problem on Windows 7, I work on MacOS.
It looks like there’s a problem with your AIR SDK setup – check environment paths, etc.
Hi.
I just found the problem.
To export a release, the iOS packager must have access to http://www.apple.com/DTDs/PropertyList-1.0.dtd and I don’t have Internet access for my development pc…
When using this extension you really cannot package the IPA on Windows…
Appearantly, when using this extension you cannot package the IPA on Windows. I tried it. Didn’t work. You have to package it with the command line tool on Mac.
So get a Mac or install WMware. You still need a Mac to upload the app to iTunes you know
Quite possible. Since iOS SDK is available only on MacOS X and the application needs to be code signed with APNs certificates the compilation will propably fail on Windows.
Hi.
I get an error:
ld: file not found: %ADT_ENV_VAR_21%
Compilation failed while executing : ld64
I’m using xp + flex 4.6
Can you help?
Thanks
I’m having the same problem did you find a solution?
(using windows 7, AIR 3.1, compiling it like shown here http://www.youtube.com/watch?v=YAkuEdYbQJQ – works for other native extensions)
I didn’t try to make it work on Windows. I think it’s possible.
Is there any way to use this with flash cs5.5 and AIR 3.1?
Yes, you need to replace AIR 2.6 which comes with Flash CS 5.5 with AIR 3.1 and you should be able to use any native extension.
I did the overlay of SFK and change the ane to swc for use with flash. The problem is that when I compile the swf I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at pl.randori.air.nativeextensions.ios::APNSExtension/registerForRemoteNotifications()[/Users/piotr/Projekty/flashsimulations/APNExtension/ANE-NativeMail-AIR-library/src/pl/randori/air/nativeextensions/ios/APNSExtension.as:34]
This happens with the following function:
apnServiceExtension.registerForRemoteNotifications();
It does not work when I put the IPA in the ipad neither.
Could you guide me with this?
Thanks!
Follow this manual – http://kb2.adobe.com/cps/908/cpsid_90810.html
1. In point 12) set version to 14 instead of 13.
2. Change namespace number to 3.1
Publish the .fla a few times (File->Publish).
I have followed all the steps you mentioned but still not working.
I try to compile the IPA by command line and add the entitlements by hand, but in this case I cant install on the device.
It may be a bug in the entitlements?
Application identifier in provisioning profile and id in AIR app descriptor must match, iTunes won’t install an application on the device otherwise.
This isn’t directly relatet to Entitlements. If entitlements were wrong you’d only get APNs not working.
I’ve found the problem. I was on configuring settings xml, this site explains:
http://help.adobe.com/en_US/air/build/WS597e5dadb9cc1e0253f7d2fc1311b491071-8000.html#WSb2a114358507af456b18bc461311b6bc0a8-7ffd
now works, but there’s a simple question: How do I delete the badge indicator from the app icon?
Is it possible send notification direct on device, роint-to-point without server side( php and ssl://gateway.sandbox.push.apple.com:2195)?
No. Only APN Service can do that.
Hello Piotr Koscierzynski!Could u plz tell us how to get the Device Token?
Device token can only be accessed using Objective-C code. My extension does exacly that and then returns the token back to ActionScript as a StatusEvent.
Do u mean that i shall make .m file implement UIApplicationDelegate and define the method:
UIApplication *) application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken
-(void) application
?Then change the default delegate of UIApplication?
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?
hi,
i’m working with FB1.6, Air 3.1 on windows 7, but i’ve compiling errors as barryzjk…
can you help us?
regards
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.
Works! (with urbanairship also)
Is there any way to get rid of the alert popup with the json notification?
Also -
Are you planning to also support local notifications, or at least setting the number for the icon badge? That would make a lot of sense and make your extension even awesomer
This extension is just a quick demo I made, but we have a pro version that we’re using in our projects with a few additional features and everything properly organized.
Are you planning on releasing some of that? Complied? Commercial? Anything?
That’s quite a buildup you made here..
Please. share your native code ;D
We are using this extension in a couple of projects for our clients and we do not plan to release the source of this extension right now.
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.
When you run the example application, you can find the device token in TextArea component or popup.
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
Same problem here, pop-up + no token back….
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!
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 ??