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.




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?
Can you make a simple video tutorial
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?
Did you get this sorted? I would also like to use this is a proper project but don’t want the popup messages showing.
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..
Any news on that? I would like to be using the pro version! Or a version without the popups are connecting.
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….
Same here, i get first 2 messages, but no token. I checked and re-checked my provisioning profile (generated after i enabled apn on portal) and app.xml several times but to no avail…
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 ??
Dear Piotr,
Thanks a lot for your great tutorial. I created an application on developer.apple.com and configured APNs already. I export the ipa file from Flash Builder 4.6 using MAC. Everything seems fine except the thing that I stuck at the step “get APNS device token”. When I push the button to register APN, I just receive 2 first messages and it stops at “registering device to APNS”.
Even when I tried with your release source code (I modifid the app id to mine already), that issue still remains. Could you please tell me which step I missed or you guess which step of mine has the problem.
Thanks and BEST Regards,
Good afternoon,
I am having some trouble with this. It’s a weird error and I haven’t found anyone with the same issue yet.
The thing is that when I try install my app on my iPhone3GS, it doesn’t finish and the device raises an “iTunes Sync > Error installing “”" and that’s it.
I realized that the problem comes when I add the Entitlements section on the application descriptor. Without it, the app is installed normally but of course the registerForRemoteNotifications function won’t work and will raise and error saying that the aps-environment isn’t defined and some other stuff related to this matter.
If anyone has a clue about this, let me know please, I’m having a hard time with this.
Cheers!
Problem solved.
The issue was that the provisioning profile I was using was created before push notifications were enabled for the AppID, so it lacked some data related to this matter.
To solve this I just created a new provisioning profile for the app and it all worked smoothly.
Tried compiling for AIR3.2 for ios with the newest ADT.
I can confirm that ADT compiling under windows does not work. In my case it throws:
ld: file not found: %adt_env_var_32%
Compilation failed while executing : ld64
My guess is that this error occurs because i am missing the iOS SDK from XCode.
If this is not the case – i would really appreciate any help you can provide.
I will try to compile in OSX, but that just seems like such a hassle.
Hello,
same error
can you help me
error:
Error occurred while packaging the application:
Exception in thread “main” java.lang.Error: Unable to find named traits: pl.randori.air.nativeextensions.ios::APNSExtension
at adobe.abc.Domain.resolveTypeName(Domain.java:231)
at adobe.abc.Domain.resolveTypeName(Domain.java:148)
at adobe.abc.GlobalOptimizer$InputAbc.resolveTypeName(GlobalOptimizer.java:272)
at adobe.abc.GlobalOptimizer$InputAbc.resolveSlotType(GlobalOptimizer.java:946)
at adobe.abc.GlobalOptimizer$InputAbc.resolveType(GlobalOptimizer.java:535)
at adobe.abc.GlobalOptimizer$InputAbc.resolveTypes(GlobalOptimizer.java:448)
at adobe.abc.LLVMEmitter.generateBitcode(LLVMEmitter.java:327)
at com.adobe.air.ipa.AOTCompiler.convertAbcToLlvmBitcodeImpl(AOTCompiler.java:472)
at com.adobe.air.ipa.BitcodeGenerator.main(BitcodeGenerator.java:82)
Compilation failed while executing : ADT
If anyone knows how to really do it provide a video…
provide a video…
Hi Piotr,
First of all, thanks for the great work. I’m using your mail extension in an app (works great!!) and now implementing your push extension. But I get an error :
[exec] ld: duplicate symbol _OBJC_IVAR_$_MailComposerHelper.context in /var/folders/fm/xskr6spx457bnd4hkm6ff_kc0000gn/T/03e3f7df-1982-4Compilation failed while executing : ld64
[exec] 169-a889-dbce599e3351/libpl.randori.air.nativeextensions.ios.MailExtension.a(MailComposerHelper.o) and /var/folders/fm/xskr6spx457bnd4hkm6ff_kc0000gn/T/03e3f7df-1982-4169-a889-dbce599e3351/libpl.randori.air.nativeextensions.ios.APNSExtension.a(MailComposerHelper.o)
[exec] Result: 12
Usign AIR 3.3 (yesterday released) and Flex 4.6. Package with ipa-test-interpreter.
Any idea?
How do I specify my own push server?
ok nevermind
did not read the linked tutorial.
Thanks.
I am trying to use the extension with other extensions such as
http://lancelotmobile.com/blog/admob-ane/
it is giving errors, as it seems you are using the same function name to initialize the extension:
Multiple ANEs with the same initializer ExtIntizilizer
and it wont work, is there a way you can provide us with a build that uses a more custom function name so it won’t conflict in the future?
Thanks
it hangs on “Will send request to APNS” same issue as reported above.
Any fixes?
Same here:
2 lines:
- Received event: Will send request to APNS
- Received event: Registering device to APNS
1 popup:
AIR APN Event
Registering to APNS
Any fix for this? Is the binary outdated?
Same here!
Any idea?
sorry, I got some problem can you help me
The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.
(0xE8008016).
how can i get the device token with flash as3?
Thanks a lot for this ANE. Registration work fine but i don’t receive notification.
Does ANE work in Production mode ? (I changed key aps-environment to production and get-task-allow to false )
How do you know which gateway ANE is connected to ?
gateway.push.apple.com or gateway.sandbox.push.apple.com ?
Thanks for you reply
Check again and regenerate app’s provisioning profile. It’s a certificate issue, not related to the ANE itself.
Sandbox is used only for apps that are not in AppStore, ANE does not care about which server sends the message.
Hey Piotr, THANKS for the ANE for APN!!
I am having a similar issue with several others who commented with getting the device token.
I am able to see the two events firing back:
Received event: Will send request to APNS
Received event: Registering device to APNS
Though no Device token, if I understand correctly the ANE is taking note of it, though, how should I listen to it?
This is a very important ANE, and any help would go a looong way!
Check the entitlements again and regenerate app’s provisioning profile if you have to. It’s a certificate issue, not related to the ANE itself.
You fail security validation at Apple servers and that’s why it doesn’t work.
Hi,
I redid the plugin in objective-c it is working, I am not sure why yours is not, but I am guessing it is related to:
http://stackoverflow.com/questions/9204993/push-notification-ios-native-extension-for-adobe-air
I am using the same entitlements so the issue is from your plugin.
regards,
joseph.
Maybe it’s related to a newer iOS and AIR SDK version, maybe Adobe changed something.
This version of ane is working for sure when app is build using AIR 3.2 and up to iOS 5.0.
I recently got it updated (compiled with iOS SDK 5.1 and added Android support) and it’s working with AIR 3.3 beta on new iPad running iOS 5.1 and iPhone 3GS running iOS 5.1.
I’ll try to post an update in my free time.
Can you give more details (device, iOS version, AIR version) ?
I am facing issue while installing the app to the device.
First I forgot to add the aps-environment key to the entitlements file. I was able to install it but got error that aps-environment was not set.
Now when I have added it, I am not able to install the app. It starts installation and stops with an error.
Any idea what might be wrong?
Ok. I was able to get this fixed. It now runs fine on iOS 5.1 and compiled with AIR 3.2
I can’t get it to work either. I use CS6 and am not entire what to put in the Entitlement sections given the blanked out examples. Does it need the random hex string Apple provides you with? and what’s before the .* in the key section?
I am convinced that my provisioning file has the push notifications in it (I regenerated and downloaded it 3 times!) but still the device token is not returned.
I also never found an answer to how to switch the pop-ups off. So totally stuck really and any more suggestions would be appreciated.
I have written a blog post here with points to keep in mind while using this ANE: http://rjdesignz.com/adobe-air/apple-push-notificationsapns-in-flex-mobile-air-app/ I was able to run the Push Notifications on iOS 5.1 device with AIR SDK 3.2
HI piotr,
Google change Cloud Messaging System !
Normaly, old ANE must be work with the new system.
Instead of the email adress, put your new projectId.
Do you know if something change in the app xml descriptor ?
Thanks.
Thierry
Hey!
Great tutorial, works fine!
But do I have to register my App by every launch? And is it possible to prevent the notifications on registration? I always get like “AIR APN Event – successfully registered to APN Service. Device token: …”
Thanks!
Hi!
Great tutorial, works fine!
Is there a way to turn off all the dialogs box?
Thanks!
Perry