Difference between revisions of "Setup Push notifications for iOS or Android"

From Sky Networks Wiki
Jump to navigation Jump to search
Line 88: Line 88:
  
 
   2.1 The push can be used in diaplan like:
 
   2.1 The push can be used in diaplan like:
     <action application="lua" data="/home/skynet/sky/scripts/sofia_push.lua external2 1001 1002", inline="true"/>
+
     <action application="lua" data="/home/skynet/sky/scripts/sofia_push.lua external2 1001 1002" inline="true"/>
  
  

Revision as of 15:32, 2 August 2019

Click Here to return to the the SkyPhone Main Screen: Back

Push notifications are used to notify the user of incoming calls and start SkyPhone when it is not running. If Skyphone is running, it will simply receive the call and start ringing.

To setup push notifications requires 2 things:

1. An updated mod_sofia.so module which you can obtain from Sky Networks.

2. mod_sofia configuration: It is configured as follows:


The SkyDANCE SkyPhone for iOS and Android is already setup to use push messaging.

However if you want to incorporate your own solutions

Click here for instructions on how to setup firebase cloud messaging on your app. https://firebase.google.com/docs/cloud-messaging


Click here for instructions on how to setup your push notification certificate for Apple. This is required for apple notifications even if you use firebase for the push instead of APN (Apple Push Notifications)

https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server

https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns

You can also just use the provisionator from onesignal and it will do everything for you. (much easier)

https://onesignal.com/provisionator#


Once it's setup you can access

a) For google firebase you will need your Legacy server key - which can be found under your project settings, cloud messaging tab.

b) For Apple you will need the push certificate from their developer console. This file should be put into he ios push certification is put into the /home/skynet/sky/bin/Certs folder There is a script (genpems) to convert the downloaded .p12 files into the required pem certificates. Edit the script as necessary to create production or dev certificates. The files that are needed for push are: (If these are generated by by the provisionator or some other tool, you might just get one .pem file. This same file can be copied to the key and cert.pem files)

apns-dis-key.pem
apns-dis-cert.pem

or

apns-dev-key.pem
apns-dev-cert.pem

The configuration file is located in /home/skynet/sky/conf/autoload_configs/sofia.conf.xml

 <!-- push server -->
    <-- ios skyphone has a base64 encode. This variable is used to check that.-->
    <param name="is-ios-encode" value="1"/>
    <!--If there is base64 encode, set this value. But there is no base64 encode in Skyphone. -->
    <param name="is-android-encode" value="0"/>
    <!--Send push for calls where the phone is not registered (otherwise the push script needs to be put in the dialplan (in the dialplan is the recommended way)) -->
    <param name="is-push-every-call" value="0"/>
    <!--Use the Apple dev certificate or production certificate. 0 - use production certificate and production push server 1 - use sandbox and dev certificate -->
    <param name="is-dev-cert" value="0"/>
    <!--push type. 1:notification, 2:data. Currently, we don't support mixture of notification and data. -->
    <param name="push-method" value="1"/>
    <!--IOS push use FCM or not. If not, will use APNS-->
    <param name="ios-push-use-fcm" value="0"/>
    <!--FCM push URI. Normally it would not change-->
    <param name="android-push-url" value="https://fcm.googleapis.com/fcm/send"/>
    <!--API key of the app when created on google developer console. Product settings, cloud messaging - Legacy server key-->
    <param name="android-api-key" value="AIzaSyCE5l74KKPbOyWMZ-l2raqtUaD6FY2X0Y8"/>
    <!--The log file for push notifies-->
    <param name="push-log-file" value="/home/skynet/sky/log/sky_push.log"/>
    <!--It will use the "fs_cli -x" to call the API command to check endpoint state. Set the path of the fs_cli/sky_cli-->
    <param name="fs-cli" value="/home/skynet/sky/bin/fs_cli"/>
    <!--If the destination is UNREGISTER or EXPIRED, it's the wait time before destination's phone returns REGISTER message. Otherwise, it's not used.-->
    <param name="invite-wait-time" value="10"/>
  


2. push server Usage.

  There should be a script called pushtest to try it in the sky/bin directory
 Here is the source:
  1. !/bin/bash
  2. Send a push notify to a client
  3. $1 - calling number
  4. $2 - called number

fsc "sofia_push external2 $1 $2

 skydance push is an API command. It has 3 argments. The usage is:
  sofia_push <profile_name> <calling_number> <called number>


  2.1 The push can be used in diaplan like:
   <action application="lua" data="/home/skynet/sky/scripts/sofia_push.lua external2 1001 1002" inline="true"/>


3. The push token that is used can be found in the registration message in the X-Mobile header. Registrations can be seen in the sky/log/sky_sbc.log file. Here's an example:

Android: X-Mobile: os=android;token="abcyU8K7sf8:APA91bEAX8-WwrpIWSQ-cwAzgBAba_JFHVtAGPVSfeVM1Mf5LnygH1HRfkMskFD0RmQeLcRofg3Q6mrmzmSuKlzvZzdpkO7om12I3KQUlp0r7d6PNNne2K7NFGr6W463rQTJJIoowoow"

iOS: X-Mobile: os=ios;token="hDcyb5glkvfGoDY96Em/QQ8lZ3k+3ZpKL/ZUDQz/Cpw=" -

Note: For iOS the token is base64 encoded in the SIP X-header so you will need to pull the actual token from the push notify in a line like this:

Sending APN to Device with token:8e6adc4d55a27d2fa9da9a8ebe5451e4547b640511519ef07aae045630dea607