Abode Air

Integration of push notifications on Android and iOS using devdodev SDK for Adobe Air

Push Notifications are availible only for iOS and Android.

Android push notifications

Obtaining configuration file for firebase push notifications

Go to Firebase console and then to your project or create a new one.

Current project:

New project:

Save the google-services.json file and add it to your app so that it is placed inside the Assets folder in a ready .apk file. If you use Flash Builder IDE simply copy it in the root folder, Flash Builder will do the rest for you.

Implementation to app

  1. Update Adobe Air SDK. Pay attention that version of the Adobe Air SDK should be at least 22.0, otherwise FCM classes will not be imported into your project. However, you still can use Analytics, but application will not be able to accept Push Notifications.

  2. Add dependencies to your project. These libraries are located in the same archive with com.devtodev.SDK.ane extension in the dependencies folder. These extensions contain firebase, gps и android-support libraries Java, that are used for sending Push Notifications. If you have already imported firebase-auth, firebase-common, firebase-iid, firebase-messaging, play-services-auth, play-services-base, play-services-basement, support-v4 or they are included in other extensions, you don't need to import them again. In any case, we recommend to use data from the library of a version not lower than 25. Add the following to the manifest file of your app:

    <application>
        <extensions>
            <extensionID>com.devtodev.air.extensions.gps-auth</extensionID>
            <extensionID>com.devtodev.air.extensions.gps-base</extensionID>
            <extensionID>com.devtodev.air.extensions.gps-basement</extensionID>
            <extensionID>com.devtodev.air.extensions.supportv4</extensionID>
            <extensionID>com.devtodev.air.extensions.firebase-auth</extensionID>
            <extensionID>com.devtodev.air.extensions.firebase-common</extensionID>
            <extensionID>com.devtodev.air.extensions.firebase-iid</extensionID>
            <extensionID>com.devtodev.air.extensions.firebase-messaging</extensionID>
            <!-- this library should be already added for analytics -->
            <extensionID>com.devtodev.SDK</extensionID>
            ...
        </extensions>
    </application>
  3. Add the following to your application's manifest:

    <!--Replace 'com.example.application' to your package -->
    <manifest package="com.example.application" ...>
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
        <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
    	<application>
    		<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
                        
            <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" >
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                    <category android:name="com.example.application" />
                </intent-filter>
            </receiver>
                        
            <service android:name="com.devtodev.push.logic.DTDFcmMessagingService" android:exported="false">
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT"/>
                </intent-filter>
            </service>
                        
            <service android:name="com.devtodev.push.logic.DTDFcmInstanceIdService" android:exported="false">
                <intent-filter>
                    <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
                </intent-filter>
            </service>
                        
    		<receiver android:name="com.devtodev.push.logic.PushClickReceiver" android:enabled="true" android:exported="true">
    		    <intent-filter>
    			    <action android:name="com.devtodev.android.push.CLICKED" />
    			</intent-filter>
    		</receiver>
    					
    		<activity android:name="com.devtodev.push.logic.PushHandlerActivity"/>
    	</application>
    </manifest>
  4. Add the following imports to your source:

    import com.devtodev.sdk.push.DevToDevPushManager;
    import com.devtodev.sdk.push.logic.ActionButton;
    import com.devtodev.sdk.push.logic.PushMessage;
  5. Add the push notifications initialization before the DevToDev.init(appKey:String, appSecret:String) method was called:

    DevToDevPushManager.setOnFailedToRegisteredForPushNotifications(onPushTokenFailed);
    DevToDevPushManager.setOnRegisteredForPushNotifications(onPushToken);
    DevToDevPushManager.setOnPushNotificationsReceived(onPushReceived);					
    DevToDevPushManager.setOnPushNotificationOpened(onPushOpened);					
    DevToDevPushManager.setPushNotificationsEnabled(true);

    onPushToken, onPushTokenFailed, onPushReceived and onPushOpened are the functions that take following arguments:

    /**
    * @param token - push token
    */
    protected function onPushToken(param:String):void {
    }
    			
    /**
    * @param error - error message  
    */
    protected function onPushTokenFailed(param:String):void {
    }
    			
    /**
    * @param pushData - Dictionary with push message and custom push fields
    */
    protected function onPushReceived(pushData:Dictionary):void {
    }
    			
    /**
    * @param message - PushMessage. Represents toast notification message
    * @param button - ActionButton. Represents toast notification button that was clicked. Could be null if notification body was clicked
    */
    protected function onPushOpened(message:PushMessage, button:ActionButton):void {
    }

Changing the application settings in devtodev system

1. Proceed to Setting -> PUSH NOTIFICATIONS:

2. Insert the previously received Server API Key to the API Key field in Push notifications section.

3. If the Server API Key is correct, you will see the following result

Creating a new push-notification in devtodev interface

  1. Open PUSH NOTIFICATIONS section and click on 'Add new campaign' button

  2. Fill in campaign name, select an app for delivery

  3. Choose user group to send a message. You can choose existing segment or create a new one.

  4. Enter notification details

  5. Make some tests and correct the message if it's required

  6. Schedule the delivery

  7. That's it!

You can create a campaign only after at least one push token comes from devtodev SDK integrated to your application. Otherwise the app will not be displayed in the list.

iOS push-notifications

To enable Push Notifications, please perform the following actions:

  1. Add the application to your space in devtodev system

  2. Generate Developer or Production Certificate for the application and get Private key file (.p12) on its basis

  3. Submit the data to the application settings in devtodev system

  4. Integrate devtodev SDK to the application (see the “SDK integration” division to learn more about integrating and initializing devtodev SDK)

  5. Add several lines of the code to switch in the push notification to the SDK

  6. Create a campaign for sending push notifications in “Push” section

Certificate generation

  1. Open "Keychain access" utility (Launchpad → Other) and choose "Request a Certificate From a Certificate Authority" option. 21.jpg

  2. Fill in all requied fields in Certificate Assistant window, set flag an "Saved on disk" item and click "Continue". Save the file. 22.jpg

  3. Log in at iOS Provisioning Portal. Open "App IDs" section, choose your app and click "Edit". 23.jpg

  4. At first, you need to generate Certificate Signing Request. We have already done it, so you can just click "Continue".

  5. At next step you need to upload the CSR to the Apple server. Choose the CSR-file and click "Generate".

  6. You'll need to repeat this process to generate the Production Certificate when your app will be ready for release. All steps are the same.

Convert iPhone developer certificate into a P12 file on Mac OS

Follow these steps to export the certificate from Apple web-site to the P12-file:

  1. Open "Keychain access" application

  2. If the certificate hasn't been added to keychain access yet, choose "File" → "Import". Find the certificate file (CER-file) provided by Apple

  3. Choose "Keys" section in "Keychain access" application

  4. Choose personal key associated with your iPhone developer certificate. Personal key is identified by open certificate associated with it "iPhone developer: ". Choose "File" → Export objects. Save key as .p12

  5. You'll be suggested to create a password which is used when you need to import the key to another computer.

Convert iPhone developer certificate into a P12 file on Windows OS

Convert Apple certificate file to the PEM-file. Start the following command-line operation from bin catalog OpenSSL.

openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM

Convert personal key from Mac OS keychain to the PEM-key:

openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem

Now you are able to create P12-file using PEM-key and iPhone developer certificate:

openssl pkcs12 -export -inkey mykey.key -in developer_identity.pem -out iphone_dev.p12

If you are using key from Mac OS keychain than choose PEM-version created at previous step.

Otherwise you can use OpenSSL key for Windows OS.

Upload the certificate to the site

Upload the .p12-file into Integration section of application settings panel (Settings -> PUSH NOTIFICATIONS):

After the certificates has been generated you can start to integrate Push SDK into you app.

SDK Integration

  1. Add the following to your application's manifest. Don't forget that the minimum supported version is iOS 7:

    <iPhone>
          <InfoAdditions><![CDATA[
             <key>MinimumOSVersion</key>
             <string>7.0</string>
    		 <key>UIDeviceFamily</key>
    		 <array>
    		    <string>1</string>
    			<string>2</string>
    		 </array>
             ...
    	 ]]></InfoAdditions>
    
         <Entitlements>
     	    <![CDATA[
            	<key>aps-environment</key>
             	<string>development</string>
            ]]>
         </Entitlements>  
    </iPhone>

    Attention! If you use Production Certificate for signing application package, don't forget to change "development" value to "production".

  2. Add the following imports to your source:

    import com.devtodev.sdk.push.DevToDevPushManager;
    import com.devtodev.sdk.push.logic.ActionButton;
    import com.devtodev.sdk.push.logic.PushMessage;
  3. Add the push notifications initialization before the DevToDev.init(appKey:String, appSecret:String) method was called:

    DevToDevPushManager.setOnFailedToRegisteredForPushNotifications(onPushTokenFailed);
    DevToDevPushManager.setOnRegisteredForPushNotifications(onPushToken);
    DevToDevPushManager.setOnPushNotificationsReceived(onPushReceived);					
    DevToDevPushManager.setOnPushNotificationOpened(onPushOpened);					
    DevToDevPushManager.setPushNotificationsEnabled(true);

    onPushToken, onPushTokenFailed, onPushReceived and onPushOpened are the functions that take following arguments:

    /**
    * @param token - push token
    */
    protected function onPushToken(param:String):void {
    }
    			
    /**
    * @param error - error message  
    */
    protected function onPushTokenFailed(param:String):void {
    }
    			
    /**
    * @param pushData - Dictionary with push message and custom push fields
    */
    protected function onPushReceived(pushData:Dictionary):void {
    }
    			
    /**
    * @param message - PushMessage. Represents toast notification message
    * @param button - ActionButton. Represents toast notification button that was clicked. Could be null if notification body was clicked
    */
    protected function onPushOpened(message:PushMessage, button:ActionButton):void {
    }
  4. Compile and run the app. You will need a device, because simulator does not support push notifications.

Xcode will automatically choose new provisioning profile. If an error occurred during the launch make sure that there is a correct profile set in the Code Signing Identity. You'll be asked to confirm push notifications. An app will request permission only once, if user confirm it - notifications will be accepted otherwise he wont get any push messages from your app. User can change it in device settings.

Creating a new push notification in devtodev interface

1. Open PUSH NOTIFICATIONS section and click on "Add new campaign" button.

2. Fill in campaign name

You can create a campaign only after at least one push token comes from devtodev SDK integrated to your application. Otherwise the app will not be displayed in the list.

3. Choose user group to send a message. You can choose existing segment or create a new one.

4. Enter notification details

5. Test push notification (or skip this step)

6. Confirm push gateway

7. Schedule the delivery

8. That's it!

Last updated