19.11.2012 Views

Building Adobe AIR Applications

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CREACIÓN DE APLICACIONES DE ADOBE <strong>AIR</strong><br />

Desarrollo de aplicaciones de <strong>AIR</strong> para dispositivos móviles<br />

subscribeOptions.notificationStyles= preferredStyles;<br />

tt.text += "\n After Preferred notificationStyles:" +<br />

subscribeOptions.notificationStyles.toString() + "\n";<br />

remoteNot.addEventListener(RemoteNotificationEvent.TOKEN,tokenHandler);<br />

remoteNot.addEventListener(RemoteNotificationEvent.NOTIFICATION,notificationHandler);<br />

remoteNot.addEventListener(StatusEvent.STATUS,statusHandler);<br />

this.stage.addEventListener(Event.ACTIVATE,activateHandler);<br />

}<br />

// Apple recommends that each time an app activates, it subscribe for<br />

// push notifications.<br />

public function activateHandler(e:Event):void{<br />

// Before subscribing to push notifications, ensure the device supports it.<br />

// supportedNotificationStyles returns the types of notifications<br />

// that the OS platform supports<br />

if(RemoteNotifier.supportedNotificationStyles.toString() != "")<br />

{<br />

remoteNot.subscribe(subscribeOptions);<br />

}<br />

else{<br />

tt.appendText("\n Remote Notifications not supported on this Platform !");<br />

}<br />

}<br />

public function subsButtonHandler(e:MouseEvent):void{<br />

remoteNot.subscribe(subscribeOptions);<br />

}<br />

// Optionally unsubscribe from push notfications at runtime.<br />

public function unSubsButtonHandler(e:MouseEvent):void{<br />

remoteNot.unsubscribe();<br />

tt.text +="\n UNSUBSCRIBED";<br />

}<br />

public function clearButtonHandler(e:MouseEvent):void{<br />

tt.text = " ";<br />

}<br />

// Receive notification payload data and use it in your app<br />

public function notificationHandler(e:RemoteNotificationEvent):void{<br />

tt.appendText("\nRemoteNotificationEvent type: " + e.type +<br />

"\nbubbles: "+ e.bubbles + "\ncancelable " +e.cancelable);<br />

for (var x:String in e.data) {<br />

tt.text += "\n"+ x + ": " + e.data[x];<br />

}<br />

}<br />

// If the subscribe() request succeeds, a RemoteNotificationEvent of<br />

// type TOKEN is received, from which you retrieve e.tokenId,<br />

// which you use to register with the server provider (urbanairship, in<br />

// this example.<br />

public function tokenHandler(e:RemoteNotificationEvent):void<br />

{<br />

tt.appendText("\nRemoteNotificationEvent type: "+e.type +"\nBubbles: "+ e.bubbles<br />

Última modificación 30/10/2012<br />

117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!