Home

Awesome

NOTICE: This ANE is no longer managed. Instead you can use the Firebase FCM ANE. We are leaving this repository as it is only for your reference.

GCM ANE V5.0.1 for Android+iOS

GCM ANE let's you use Google cloud messaging on Android and iOS to send push notifications (remote notifications) to your app users.

asdoc

find the latest asdoc for this ANE here.

Air Usage

import com.myflashlab.air.extensions.gcm.Gcm;
import com.myflashlab.air.extensions.gcm.GcmEvent;

// set this to false when you are using your production certificate. (this property must be set before you initialize the extension with new Gcm(...)
Gcm.isSandbox = true;

var _ex:Gcm = new Gcm(ANDROID_SENDER_ID, IOS_SENDER_ID);
_ex.addEventListener(GcmEvent.REGISTERED, onRegIdReceived);
_ex.addEventListener(GcmEvent.UNREGISTERED, onUnregistered);
_ex.addEventListener(GcmEvent.ERROR, onError);
_ex.addEventListener(GcmEvent.MESSAGE, onMessage);

trace("regId = " + _ex.getRegId); // will return null or an empty String if you have not registered yet

_ex.register();
//_ex.unregister();

function onError(e:GcmEvent):void
{
    trace("onError: ", e.param);
}

function onRegIdReceived(e:GcmEvent):void
{
    trace("onRegistered: ", e.param);
}

function onUnregistered(e:GcmEvent):void
{
    trace("onUnregistered: ", e.param);
}

function onMessage(e:GcmEvent):void
{
    trace("onMessage: ", e.param);
}

Air Usage - InvokeEvent.INVOKE

NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);

private function onInvoke(e:InvokeEvent):void
{
	NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE, onInvoke);
	
	// on iOS, you will receive the GCM message as an object containing a parameter named "aps" which holds a string.
	// it's your job to parse that string and read it's information OR you can simply wait for the GcmEvent.MESSAGE event
	// to be called which 'usually' happen on iOS side when user opens the app by clicking the notification
	
	if (e.arguments.length > 0)
	{
		trace("The app has been run by clicking on the notification");
		
		try
		{
			var obj:Object = e.arguments[0];
			
			if (obj.aps)// we understand that this is coming for iOS
			{
				// extract the information we need. we are sending the gcm message including an "info" node. so we can get the "info" value like this.
				trace("info = " + e.arguments[0]["gcm.notification.info"]);
			}
		}
		catch (err:Error) // if it's not iOS, then it's Android.
		{
			var arr:Array = String(e.arguments[0]).split("://");
			trace(decodeURI(arr[1]));
		}
	}
}

Air .xml manifest

<!--
FOR ANDROID:
-->
<manifest android:installLocation="auto">
			
			<!--
			
				IMPORTANT: change all "air.com.doitflash.gcm" to your own package name. (notice the air. at the beginning)
				if your package name is "com.site.app" Android automatically adds air. to its beginning. so your Android package
				name will be actually "air.com.site.app" but on the iOS, it is still "com.site.app" with no change
			
			-->
		
		<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
		
		<!-- Required for gcm access -->
		<uses-permission android:name="android.permission.INTERNET" />
		<uses-permission android:name="android.permission.GET_ACCOUNTS" />
		<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
		<permission android:name="air.com.doitflash.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
		<uses-permission android:name="air.com.doitflash.gcm.permission.C2D_MESSAGE" />
		
		<!-- Required for waking up the device when gcm msg is arrived -->
		<uses-permission android:name="android.permission.WAKE_LOCK" />
		
		<!-- if gcm tasks are set for future, you need this to make sure timers are all set even after user restarts their device -->
		<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
		<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
		
		<!-- Required for gcm notification to access the vibrator -->
		<uses-permission android:name="android.permission.VIBRATE" />
		
		<application>
			<activity>
				<intent-filter>
					<action android:name="android.intent.action.MAIN" />
					<category android:name="android.intent.category.LAUNCHER" />
				</intent-filter>
				<intent-filter>
					<action android:name="android.intent.action.VIEW" />
					<category android:name="android.intent.category.BROWSABLE" />
					<category android:name="android.intent.category.DEFAULT" />
					<data android:scheme="air.com.doitflash.gcm" />
				</intent-filter>
			</activity>
		
			<!-- Register the required listeners to receive gcm when app is closed -->
			<receiver android:name="com.doitflash.gcm.handler.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
				<intent-filter>
					<action android:name="com.google.android.c2dm.intent.RECEIVE" />
					<category android:name="air.com.doitflash.gcm" />
				</intent-filter>
			</receiver>
			<service android:name="com.doitflash.gcm.handler.GcmMessageHandler" />
			<receiver android:name="com.doitflash.gcm.alarm.alarmTypes.Alarm_Notification" />
			
			<!-- if gcm tasks are set for future, you need this to make sure timers are all set even after user restarts their device -->
			<receiver android:name="com.doitflash.gcm.alarm.RebootAutoStartAlarms">
				<intent-filter>
					<action android:name="android.intent.action.BOOT_COMPLETED" />
				</intent-filter>
			</receiver>
			
			<!-- Required for waking up the device when gcm notification arrives -->
			<activity android:name="com.doitflash.gcm.alarm.WakeActivity" android:theme="@style/Theme.Transparent" />
			
		</application>
</manifest>




<!--
FOR iOS:
-->
	<InfoAdditions>
		<!-- iOS 6.1 is the minimum device requirement for gcm to work -->
		<key>MinimumOSVersion</key>
		<string>6.1</string>
		
		<key>UIStatusBarStyle</key>
		<string>UIStatusBarStyleBlackOpaque</string>
		
		<key>UIRequiresPersistentWiFi</key>
		<string>NO</string>
		
		<key>UIPrerenderedIcon</key>
		<true />
		
		<key>UIDeviceFamily</key>
		<array>
			<string>1</string>
			<string>2</string>
		</array>
		
		<!-- Required for gcm ane -->
		<key>UIBackgroundModes</key>
		<array>
			<string>fetch</string>
			<string>remote-notification</string>
		</array>
		
		<!-- introduce your gcm sender id for ios here (you will introduce it again in AS3 when initializing the extension) -->
		<key>GCM_SENDER_ID</key>
		<string>000000000000</string>
		
		<key>PLIST_VERSION</key>
		<string>1</string>
		
		<!-- your iOS bundle id goes here too -->
		<key>BUNDLE_ID</key>
		<string>com.doitflash.gcm</string>
		
		<!-- Your are using gcm service, so set IS_GCM_ENABLED to true just like below -->
		<key>IS_ADS_ENABLED</key>
		<false/>
		<key>IS_ANALYTICS_ENABLED</key>
		<false/>
		<key>IS_APPINVITE_ENABLED</key>
		<false/>
		<key>IS_GCM_ENABLED</key>
		<true/>
		<key>IS_SIGNIN_ENABLED</key>
		<false/>

		
	</InfoAdditions>
		
    <requestedDisplayResolution>high</requestedDisplayResolution>
	
	<Entitlements>
	
	<!--
		You need to add all lines below just make sure to change two thing:
		1) change all "com.doitflash.gcm" to your own iOS bundle ID
		2) everywhere you see "M8DXV5X5LV" you need to enter your own provision ID instead. (HOW TO? go to your apple dev console where you are downloading your provisions from and click on edit a provision... there you will see a similar String. honestly, I don't have a clue what that is myself neither :D It's just apple's rules!
	-->
		
		<key>keychain-access-groups</key>
		<array>
			<string>M8DXV5X5LV.*</string>		
		</array>
		
		<!-- set to 'true' when debugging your app and set to 'false' when building for adhoc or distribution -->
		<key>get-task-allow</key>
		<true/>
		
		<key>application-identifier</key>
		<string>M8DXV5X5LV.com.doitflash.gcm</string>
		<key>com.apple.developer.team-identifier</key>
		<string>M8DXV5X5LV</string>
		
		<!-- set to 'development' when debugging your app and set to 'production' when building for adhoc or distribution -->
		<key>aps-environment</key>
		<string>development</string>
		
	</Entitlements>
	
	
	
	
<!--
Embedding the ANE:
-->
  <extensions>
	<extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.gcm</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.iid</extensionID>
	<extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.basement</extensionID>
    <extensionID>com.myflashlab.air.extensions.dependency.androidSupport</extensionID>
    <extensionID>com.myflashlab.air.extensions.gcm</extensionID>
  </extensions>
-->

Requirements

Commercial Version

http://www.myflashlabs.com/product/gcm-ane-adobe-air-native-extension/

GCM ANE

Tech Details

we have tried to make the AS3 API identical for both Android and iOS but there are still some differences which you should know about when implementing this extension in your project. I will explain these differences here.

Tutorials

How to embed ANEs into FlashBuilder, FlashCC and FlashDevelop
How to obtain gcm senderID + server API key for Android?
How to obtain gcm senderID + server API key for iOS?
How to setup the Air xml manifest ready to work with gcm extension?

Changelog

Sep 13, 2016 - V5.0.1

Jun 05, 2016 - V5.0.0

Feb 09, 2016 - V4.9.3

Jan 20, 2016 - V4.9.2

Dec 20, 2015 - V4.9.1

Nov 03, 2015 - V4.9

Sep 13, 2015 - V4.0

Jan 18, 2014 - V2.2

Jul 11, 2013 - V2.1

Jun 24, 2013 - V2.0

Jan 29, 2013 - V1.0