=====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. Preventivamente, ogni device che desidera ricevere le notifiche dovrà essere registrato al servizio di notifiche push su una ACS APP tramite il **device_token** inviato al server da una APP OS nativa installata nel device stesso. La registrazione comprende: * nome del canale. Il canale non va creato precendetemente, esiste in quanto il device lo usa per registrarsi; * il device token; * il tipo di servizio, legato all'OS device (ad esmpio “android” per Android) La push fatta dal server si divide in 2 parti: * **autenticazione** da parte del server, tramite un utente (se necessario admin) dell'**ACS APP**; * la **push** vera e propria, inviata ai device registrati su un certo canale. E’ possibile inviare push a una lista di device iscritti ad un determinato canale, oppure a tutti i device iscritti a quel canale. > NOTA: È possibile mandare push alla App ACS sia in modalità Development che in modalità Production (hanno due cloud link diversi). In questo caso, è importante considerare che ** app android firmate con una debug key possono ricevere push solo di tipo development, mentre app android firmate con release key possono ricevere push solo di tipo production **. Questo ovviamente previa iscrizione del token Ad ogni utente possono essere registrati diversi device, anche gli stessi su piu canali. ===Teconologie:=== Appcelerator ACS, cURL ===Referenze:=== * Google Developing Console: https://console.developers.google.com/project * http://www.titaniumtutorial.com/2013/10/acs-push-notification-using-gcm.html * http://docs.appcelerator.com/cloud/latest/#!/api/PushNotifications-method-subscribe ====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=== **RIFERIMENTO**: http://docs.appcelerator.com/platform/latest/#!/guide/Configuring_push_services-section-37551713_Configuringpushservices-ConfiguringpushservicesforAndroiddevices * 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: * Project number nella schermata di riepilogo dello stesso da usare come GCM Sender ID * una API KEY, ottenuata creando una Server Key nella sezione “APIs & Auth” -> Credentials -> Create New Key -> Server Key * Andare su Overview -> Boost your app with a Google API (Enable and API) -> Mobile APIs (Cloud Messaging for Android) * 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. Le stesse informazioni sono inserite nel tiapp.xml file, insieme anche anche alle chiavi oauth ===Configurare il servizio di push per IOS=== **RIFERIMENTO**: http://docs.appcelerator.com/platform/latest/#!/guide/Configuring_push_services-section-37551713_Configuringpushservices-ConfiguringpushservicesforiOSdevices * Questa parte è volta all’utilizzo di APN (Apple Push Notifications ] per implementare un servizio di Push Notifications verso device IOs utilizzando ACS. * Non testato, ma c’è una guida esaustiva su: [http://docs.appcelerator.com/titanium/3.0/#!/guide/Configuring_push_services-section-37551713_Configuringpushservices-ConfiguringpushservicesforiOSdevices] ====INVIARE PUSH NOTIFICATIONS==== > **NOTA:** E’ necessario utilizzare un utente admin affinchè possa fare le push per tutti i device su un canale. http://docs.appcelerator.com/cloud/latest/#!/api/Users ====REGISTRARE UN DEVICE ==== ===SINTASSI=== curl -i -X POST -F "type=" -F "device_token=" -F "channel=" "http://api.cloud.appcelerator.com/v1/push_notification/subscribe_token.json?key=&pretty_json=true" ===SOTTOSCRIZIONE=== ==req== curl -i -X POST -F "type=android" -F "device_token=APA91bHF_AHTplu57dY115i9h5qntVeLlOwKfM8YbkwM3THhhgXEB_vIxec9kBu_eNAAY4UAstU_jQc6dUTIVdvwukP-w16bIyTFEJnOCAbX5nMfLx7l3ea4XCXRLnY6xSqGnWfZKPc0rNWfWwTaB5NEzKqdfDzgio0w1v4_pFII-rcU_5VhNrU" -F "channel=push.notification" "http://api.cloud.appcelerator.com/v1/push_noti fication/subscribe_token.json?key=XC6OWeoFQGEgP6Xtfb9V0mbF9oqgicjT&pretty_json=true" ====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 un’autenticazione prima di procedere a una push. > **NOTA:** controllare che l’autenticazione sia effettivamente fatta tramite i cookie, e non sia a livello di sessione, altrimenti ACS non potrà controllare che l’utente sia un admin Il device deve essere precedentemente registrato. ===SINTASSI=== curl -b cookies.txt -c cookies.txt [ [-F “param=value”] ] "https://api.cloud.appcelerator.com/v1/users/login.json?key=" OPPURE curl -b cookies.txt -c cookies.txt -X POST -F "channel=" -F "to_tokens=[token,][everyone]" -F "payload=" "https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=OpSVzgLtcqPn5tDP96djYVHQNjEAOROU&pretty_json=true" RESPONSE: { "meta": { "status": "ok", "code": 200, "method_name": "NotifyTokens" } } ===AUTENTICAZIONE:=== ==req== curl -b cookies.txt -c cookies.txt -F "login=admin" -F "password=admin" "https://api.cloud.appcelerator.com/v1/users/login.json?key=OpSVzgLtcqPn5t DP96djYVHQNjEAOROU&pretty_json=true" ==resp== {"meta": {"code":200, "status":"ok", "method_name":"loginUser", "session_id":"dw-GBX9liki_YNu8OTchKIwO__M" }, "response":{ "users":[ { "id":"54579b36f13f3a442f003079", "first_name":"admin", "last_name":"admin", "tags":["admin"], "created_at":"2014-11-03T15:11:50+0000", "updated_at":"2014-11-03T16:16:37+0000", "external_accounts":[], “confirmed_at":"2014-11-03T15:11:50+0000", "username":"admin", "role":"admin", "admin":"true"," stats":{ "photos":{"total_count":0}, "storage":{"used":0}}, "email":"prova1@prova.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:== Ad una lista (in questo caso uno) di tokens curl -b cookies.txt -c cookies.txt -X POST -F "channel=welfare" -F "to_tokens=APA91bHF_AHTplu57dY115i9h5qntVeLlOwKfM8YbkwM3THhhgXEB_vIxec9kBu_eNAAY4UAstU_jQc6dUTIVdvwukP-w16bIyTFEJnOCAbX5nMfLx7l3ea4XCXRLnY6xSqGnWfZKPc0rNWfWwTaB5NEzKqdfDzgio0w1v4_pFII-rcU_5VhNrU" -F "payload=prova_acs" "https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=OpSVzgLtcqPn5tDP96djYVHQNjEAOROU&pretty_json=true" ==resp:== { "meta": { "status": "ok", "code": 200, "method_name": "NotifyTokens" } } ==req:== A tutti curl -b cookies.txt -c cookies.txt -X POST -F "channel=welfare" -F "to_tokens=everyone" -F "payload=prova_acs" https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=OpSVzgLtcqPn5tDP96djYVHQNjEAOROU&pretty_json=true" ==resp:== { "meta": { "status": "ok", "code": 200, "method_name": "NotifyTokens" } } ==parametri:== “channel=” è il canale su cui viene pushata la notifica “to_tokens=” contiene una lista di token 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". ====PER DEPLOYARE UN’APPLICAZIONE CHE POSSA REGISTRARSI SULL’ACS==== ===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 ===Configurare=== ti setup quick , oppure ti 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. Esempio di DEVICE_TOKEN android = APA91bHF_AHTplu57dY115i9h5qntVeLlOwKfM8YbkwM3THhhgXEB_vIxec9kBu_eNAAY4UAstU_jQc6dUTIVdvwukP-w16bIyTFEJnOCAbX5nMfLx7l3ea4XCXRLnY6xSqGnWfZKPc0rNWfWwTaB5NEzKqdfDzgio0w1v4_pFII-rcU_5VhNrU ===CROSS APP PUSH=== Luca CIOE' MI VUOI DIRE CHE LA APP1 NON DICE NIENTE AD APPCELERATOR, DA' IL TOKEN A NOI, NOI LO REGISTRIAMO SU APP2 E POI POSSIAMO INVIARE LE NOTIFICHE AI CELL CON APP1 TRAMITE IL TOKEN REGISTRATO SU APP2 ? :gift_heart:? Matteo se appcelerator non cambia la sua politica nelle prossime 12 ore.... si ! :tada: ho appositamente deregistrato la (mia) app1, che avevo registrato da smartphone ed ora riceve comunque le notifiche inviate utilizzando l'api_key dell'app2. ===NOTIFCHE TRAMITE TOKEN=== Può ritornare un HTTP 400 "Subscription Not Found" [[http://docs.appcelerator.com/platform/latest/#!/guide/Sending_and_Scheduling_Push_Notifications-section-37551726_SendingandSchedulingPushNotifications-%27Subscriptionnotfound%27error | Subscription Not Found ]] === Build === [[http://docs.appcelerator.com/titanium/3.0/#!/guide/Titanium_Command-Line_Interface_Reference-section-35619828_TitaniumCommand-LineInterfaceReference-Build | build appcelerator]] === Prove === installazione smartphone app su device collegata ad app ACS e registrazione: v * push da console v * push da curl v deregistrazione da app ACS con successiva registrazione da curl: v * push da console v * push da curl v * push da trigger v deregistrazione da app ACS con successiva registrazione da curl verso una app ACS diversa: v * push da console v * push da curl v * push da trigger v