Local Notifications is an extension that enables local notification messages to be displayed on a device. These notifications appear in the global notifications panel for iOS and Android.
Some features:
- Local notification support for iOS devices (iOS 4, 5+)
- Local notification support for Android devices
- Display local notifications with only a few lines of code
- Single API interface – your code works across iOS and Android with no modifications
- Sample project code and ASDocs reference
Sample
/** * __ __ __ * ____/ /_ ____/ /______ _ ___ / /_ * / __ / / ___/ __/ ___/ / __ `/ __/ * / /_/ / (__ ) / / / / / /_/ / / * \__,_/_/____/_/ /_/ /_/\__, /_/ * / / * \/ * http://distriqt.com * * @file TestNotifications.as * @brief * @author Michael Archbold (ma@distriqt.com) * @created Jan 17, 2012 * @updated $Date:$ * @copyright http://distriqt.com/copyright/license.txt */ package { import com.distriqt.extension.notifications.Notification; import com.distriqt.extension.notifications.NotificationIconType; import com.distriqt.extension.notifications.Notifications; import com.distriqt.extension.notifications.events.NotificationEvent; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFormat; /** * Test application for the com.distriqt.Notifications Native Extension * * @author Michael Archbold (ma@distriqt.com) */ public class TestNotifications extends Sprite { /** * Constructor */ public function TestNotifications() { super(); create(); try { Notifications.init( "your_key_here" ); message( "Press to send a notification" ); message( String(Notifications.isSupported) ); message( Notifications.service.version ); Notifications.service.addEventListener( NotificationEvent.NOTIFICATION_DISPLAYED, notifications_notificationDisplayedHandler, false, 0, true ); Notifications.service.addEventListener( NotificationEvent.NOTIFICATION_SELECTED, notifications_notificationSelectedHandler, false, 0, true ); } catch (e:Error) { message( "ERROR:"+e.message ); } } //////////////////////////////////////////////////////// // VARIABLES // private var _text : TextField; private var _count : int = 0; //////////////////////////////////////////////////////// // FUNCTIONALITY // private function sendNotification():void { var notification:Notification = new Notification(); notification.id = int(Math.random()*100); notification.tickerText = "Hello "+notification.id; notification.title = "My Notification "+notification.id; notification.body = "Hello World!"; notification.iconType = NotificationIconType.FLAG; notification.count = 0; notification.vibrate = false; // notification.playSound = true; notification.delay = 10; notification.data = "Some notification data to attach "+notification.id; try { Notifications.service.notify( notification.id, notification ); _count ++; Notifications.service.setBadgeNumber( _count ); message( "sendNotification():sent:"+notification.id ); } catch (e:Error) { message( "ERROR:"+e.message ); } } //////////////////////////////////////////////////////// // INTERNALS // private function create():void { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.addEventListener( Event.RESIZE, stage_resizeHandler, false, 0, true ); stage.addEventListener( MouseEvent.CLICK, mouseClickHandler, false, 0, true ); var tf:TextFormat = new TextFormat(); tf.size = 24; _text = new TextField(); _text.defaultTextFormat = tf; _text.width = 480; _text.height = 800; _text.selectable = false; addChild( _text ); } private function message( m:String ):void { trace( m ); _text.appendText( m + "\n" ); } //////////////////////////////////////////////////////// // EVENT HANDLERS // private function stage_resizeHandler( event:Event ):void { _text.width = stage.stageWidth; _text.height = stage.stageHeight; } private function mouseClickHandler( event:MouseEvent ):void { sendNotification(); } private function notifications_notificationDisplayedHandler( event:NotificationEvent ):void { message( event.type + "::["+event.id+"]::"+event.data ); } private function notifications_notificationSelectedHandler( event:NotificationEvent ):void { message( event.type + "::["+event.id+"]::"+event.data ); try { _count --; Notifications.service.cancel( event.id ); Notifications.service.setBadgeNumber( _count ); // Notifications.service.cancelAll(); } catch (e:Error) { } } } }