Integrating Push Notification in Flash

0 votes

hi Im new user app42 .

 
But ıcant integrating my games.
 
Because my games pure as3 Im not using flex.
 
Your example code in flex.You mathing id with key use PersistenceManager.
 
But ıcant find any way to pure as3 in flash.
 
Please help me how to solve hot to use push nativation pure as3 thanks your interesting.
 
sory my english not god

 

asked Mar 26, 2014 in App42 Cloud API-BaaS by kokarcalihakan (10 points)

1 Answer

0 votes

Hi kokarcalihakan,

                              If you want to integrate Push Notification in your pure as3 projects,please follow these steps:

  • we are using persistentMangeer just used to get registration_id that is set before , while getting  from ANE.
  • So in your as3 project just remove that code and use as it is , as required , as use as it is.it will work fine.
  • Or you can save it any of your as3 code so that you don't need to make another reuest if you register with App42 PushNotication. Just retrive last message by calling method :    'app42Push.lastMessage();' that I have used in sample

Please in case of any query , revert to us.

Thanx

answered Mar 27, 2014 by Vishnu Garg (674 points)
İm still not connecting server.ı cant reqister .Somoting wrong in my code!
ı use share object i cant register id from ane. Please share working sample code or help me where ı m wrong

my code
public function Main():void
        {
            stage.scaleMode = StageScaleMode.EXACT_FIT;
            stage.align = StageAlign.TOP_LEFT;
            stage.addEventListener(Event.DEACTIVATE, deactivate);
           
            // touch or gesture?
           
           
            // entry point
           
            // new to AIR? please read *carefully* the readme.txt files!
           
            if (App42Push.isSupported)
                {
                    app42Push = new App42Push;
                    app42Push.addEventListener(App42RegistrationEvent.REGISTER, onRegistered);
                    app42Push.addEventListener(App42PushEvent.Message, onMessage);
                    intializeApi();
                    // Checking if application was already registered in App42 service
                    //var registrationId:String = persistence.getProperty("registration_id") as String;
                    //so = SharedObject.getLocal("registration_id");
                    //message_txt.appendText("so:"+String( so))
                    //var registrationId:String =String(so)
                    //registered = registrationId != null;
                   
                    so = SharedObject.getLocal("registration_id");

                    so.flush();
                    if(so.data.registration_id!=undefined){
                        app42Push.lastMessage();
                    }
                    else{
                        app42Push.register(AppConstants.ProjectNo);
                    }
                   
                   
                }
           
           
        }
       
        private function intializeApi():void
            {
                App42API.initialize(AppConstants.ApiKey,AppConstants.SecretKey);
                App42API.setLoggedInUser(AppConstants.UserId);
                App42Log.setDebug(true);
            }
           
            private function onMessage(event:App42PushEvent):void
            {
                trace("app42 Message:", event.message);
                message_txt.appendText("app42 Message:"+String( event.message))
                app42Push.resetCount();
                //message.text=event.message as String;
            }
       
        private function deactivate(e:Event):void
        {
            // make sure the app behaves well (or exits) when in background
            //NativeApplication.nativeApplication.exit();
        }
       
       
           
        private function onRegistered(event:App42RegistrationEvent):void
            {
                trace("Registered with registration id:", event.registrationId);
                message_txt.appendText("Registered with registration id:"+ String(event.registrationId))
                // Storing registration id received from C2DM service
                so = SharedObject.getLocal("C2DM");
                so.data.registration_id = event.registrationId
                so.flush();
                //so.data["registration_id"] = event.registrationId;
                //trace(so.data["registration_id"], so.data.registration_id)
               
               // persistence.setProperty("registration_id", event.registrationId);
                App42API.buildPushNotificationService().storeDeviceToken(App42API.getLoggedInUser(),event.registrationId,DeviceType.ANDROID,new App42FlashCallback());
So for connection with server just use this one and please check that your are getting registration Id in that event.

private function onRegistered(event:App42RegistrationEvent):void
            {
               
                App42API.buildPushNotificationService().storeDeviceToken(App42API.getLoggedInUser(),
                event.registrationId,DeviceType.ANDROID,new App42FlashCallback());
               
            }
ıcant reach event:App42RegistrationEvent someting wrog the app desc. xml file i thing.
what code change in this xml file ?
    <android>
        <manifestAdditions><![CDATA[
            <manifest android:installLocation="auto">   
              <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
                <permission
        android:name="air.com.shephertz.app42.push.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="air.com.shephertz.app42.push.permission.C2D_MESSAGE" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.HARDWARE_TEST" />
    <uses-permission android:name="android.permission.VIBRATE" />
        <application>
                <receiver
            android:name="com.shephertz.app42.android.flash.push.App42GCMReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="air.com.shephertz.app42.push" />
            </intent-filter>
        </receiver>
        <service android:name="com.shephertz.app42.android.flash.push.App42GCMService" >
        </service>
           <meta-data android:name="push_title" android:value="PushNotificationSample"/>
    </application>
            </manifest>
           
        ]]></manifestAdditions>
    </android>
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...