User Tools

Site Tools


spes:node_acs

GUIDA PER LE PUSH

Risultato atteso:

Inviare notifiche PUSH da un server verso altri device registrati al servizio. È richiesto che la notifica arrivi anche se il ricevente non è UP.

Teconologie:

Appcelerator ACS, cURL

Referenze:

Settare l'environnement

E’ necessario installare cURL: [http://curl.haxx.se/dev/source.html]

NOTA: in questo documento viene mostrato come inviare notifiche ad un device Android. Tuttavia il processo è parallelo per device IOS, con i dovuti accorgimenti riportati nei link alla documentazione di Appcelerator presenti nelle prossime sezioni.

Azioni preventive

Configurare il servizio di push per Android

  • Questa parte è volta all’utilizzo di GCM (Google Cloud Messaging) per implementare un servizio di Push Notifications verso device Android utilizzando ACS (Appcelerator Cloud Services):
  • Creare un progetto nella Google Cloud Console [https://cloud.google.com/console]. In questo modo sarà possibile ottenere:
    • l’ID del progetto (nellla schermata di riepilogo dello stesso)
    • una API KEY, ottenuata creando una Server Key nella sezione “APIs & Auth”
  • Creare un’ACS app nell’ Appcelerator cloud console [https://my.appcelerator.com/apps]. Questa azione servirà per ottenere una APP KEY da utilizzare nel momento in cui le Push Notifications verranno inviate dal server ai device registrati. Inoltre, sarà necessario inserire la API KEY e il Project Number nella sezione “Android Push Configuration” in “Manage ACS” della App.

Configurare il servizio di push per IOS

INVIARE PUSH NOTIFICATIONS

In [http://docs.appcelerator.com/cloud/latest/#!/api/PushNotifications] è possibile trovare una lista dei possibili parametri da passare a una Push

Importante: ACS richiede necessariamente un’autenticazione prima di procedere a una push.
NOTA: controllare se l’autenticazione è effettivamente fatta tramite i cookie, e non sia a livello di sessione

Il device deve essere precedentemente registrato.

NOTA: a meno di controlli, è possibile per un utente registrarsi diverse volte con lo stesso utente ma diversi devices

SINTASSI

curl -b cookies.txt -c cookies.txt [ [-F “param=value”] ] https://api.cloud.appcelerator.com/v1/users/login.json?key=<APP KEY>

AUTENTICAZIONE:

req

curl -b cookies.txt -c cookies.txt -F“login=prova” -F “password=prova” https://api.cloud.appcelerator.com/v1/users/login.json?key=bMDOIoxIVfncwv1Vn9RZf9xP4n3qvGiW

resp
{
    "meta":{
        "code":200,
        "status":"ok",
        "method_name":"loginUser",
        "session_id":"VbX9Gc6pyb_M1NjAqbDcJjb4XcU"
    },
    "response":{
        "users":[
            {
                "id":"542338525b6e9117710007ea",
                "first_name":"prova",
                "last_name":"prova",
                "created_at":"2014-09-24T21:32:02+0000",
                "updated_at":"2014-09-25T11:37:36+0000",
            "external_accounts":[],
                "confirmed_at":"2014-09-24T21:32:02+0000",
                "username":"prova",
                "role":"prova",
                "admin":"false",
            "stats":{
                "photos":{
                    "total_count":0
                },
                "storage":{
                "used":0
                }
             },
            "email":"c@c.it",
            "friend_counts":{
                "requests":0,
                "friends":0
            }
        }
        ]
    }
}
Parametri:

“login=” richiede il nome utente “password=” richiede la password “key=” richiede l’APP KEY della ACS APP sul cloud appcelerator

PUSH:

req:

curl -b cookies.txt -c cookies.txt -F “channel=alert2” -F “to_ids=542338525b6e9117710007ea” -F “payload=nuovo_messaggio” https://api.cloud.appcelerator.com/v1/push_notification/notify.json?key=bMDOIoxIVfncwv1Vn9RZf9xP4n3qvGiW

resp:
{
    "meta":{
        "code":200,
        "status":"ok",
        "method_name":"Notify"
    },
    "response":{
        "push_notification":{
            "id":"5423ff889ece8cdec5004e64",
            "payload":"nuovo_messaggio",
            "channel":"alert2"
        }
    }
}
parametri:

“channel=” è il canale su cui viene pushata la notifica “to_ids=” contiene una lista di id relativi ai device iscritti al canale “payload=” contiene il testo della notifica “key=” richiede l’APP KEY della ACS APP sul cloud appcelerator

NOTA: altre proprietà possono essere settate, come i Badges. Inoltre ci sono alcune proprietà settabili solo per device Android.
NOTA: il parametro payload puo essere settato in due diversi modi, come stringa o come Json:
payload : String/Hash required
Payload to send with the push notification.
For a string, it will be sent as an alert (message notification).
For a JSON payload, you can specify the following fields as well as custom fields:
alert (String): Notification message to be displayed.
badge (String): Number to set as the badge on the application's icon. Specify postive and negative numbers with the + and - symbols to increment or decrement the current badge number, respectively.
sound (String): Filename minus the extension of the sound to play.
For native Android applications, place the file in the /assets/sound directory.
For native iOS applications, place the file in the main bundle.
For Android applications built with Titanium, place the file in the /Resources/sound directory.
For iOS applications built with Titanium, place the file in the /Resources directory.
icon (String): Available on Android only. Filename minus the extension of the icon to display in the notification center. Place the file in /res/drawable for native Android applications or /Resources for Titanium applications. Uses the app's icon by default.
title (String): Available on Android only. Title of the notification.
vibrate (Boolean): Available on Android only. If true, the device vibrates for one second.
For example:
{
“atras”: “your_user_id”,
“tags”: [
“tag1”,
“tag2”
],
“badge”: “+2”,
“sound”: “default”,
“alert” : “Push Notification Test”
}
In the above example, the atras and tags keys are custom fields, “badge” : “+2” increments the current badge value by two, “sound” : “default” plays a default system sound and “alert” : “Push Notification Test” pops up a alert window with text “Push Notification Test”.
DA VERIFICARE: come si fa a far ricevere la notifica a un server che non sia un device ??

PER DEPLOYARE UN’APPLICAZIONE CHE POSSA REGISTRARSI SULL’ACS

E’ necessario Titanium CLI.

Prerequisiti:

Installare le oracle JDK (da 6 a 8 ) Installare Node.js Installare Android SDK (per la versione, vedere http://docs.appcelerator.com/titanium/3.0/#!/guide/Installing_the_Android_SDK Installare Android NDK > 9 (per la vesrione non rischiesto) http://docs.appcelerator.com/titanium/3.0/#!/guide/Installing_the_Android_NDK

Installare la CLI con il comando npm

npm install -g titanium

Fare il login tramite npm

titanium login

Installare le SDK

titanium sdk install

Configurare

titanium setup quick , oppure titanium setup (avanzato)

SVILUPPO SU DEVICE

I device Android riceventi devono usare il pacchetto ti.cloudpush per registrarsi all’ACS sotto una applicazione ACS. In seguito ricevereanno le push notifications inviate loro sui canali corrispondenti.

I device IOS riceventi devono usare il pacchetto ti.cloud per registrarsi all’ACS sotto una applicazione ACS. In seguito ricevereanno le push notifications inviate loro sui canali corrispondenti.

spes/node_acs.txt · Last modified: 2014/10/28 11:28 by 127.0.0.1