Push Notifications

Games may use their own server to send Push Notifications to clients. If a game does not have a server Swrve may be leveraged to provide push notifications. There may also be cases where though a game has a server, you prefer to use Swrve to schedule notifications.

iOS Setup

There is not a whole lot to do for iOS to support PNs. We simply need to generate the certificate and ensure builds have the proper entitlement.

  1. Work with the producer to generate an APNS Certificate.
  2. Be sure the builds you deliver are provisioned with the aps-environment: production entitlement. To do this, you’ll need to enable PNs for the App Id of your shadow project (see Configuring Push Notifications).
  3. Send push notifications:
    • (Option A) If using your own server, your producer will provide you with the APNS Certificate generated in step 1 and you will handle configuring and sending PNs from your server.
    • (Option B) If using Swrve, export the APNS Certificate and deliver it and the password to the producer. The producer will use Swrve to configure, test, and send notifications.

NOTE: by default Swrve is configured to handle Push Notifications and the SDK auto collects the device token. If you use your own implementation, you may need to disable this. Include the following in your API settings to do so:

NSDictionary* apiSettings = @{ ...
            KONGREGATE_SWRVE_PUSH_ENABLED: @NO,
            KONGREGATE_SWRVE_AUTO_COLLECT_DEVICE_TOKEN: @NO}
[KongregateAPI initialize:gameId apiKey:apiKey withSettings:apiSettings];

Android

If Swrve is used on Android, a few additional entries will need to be added to the Android manifest and your Sender ID will need to be included with the Kongregate API initiailization. If you have your own server, you only need the producer to provide you with the Sender ID, and the rest is up to you.

<!-- these permissions are required for Swrve Push Notifications -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE_NAME.permission.C2D_MESSAGE" />
<!-- Configure the aspect of the UI -->

<!-- These @drawables refer to icons in your res directory. The Unity default is @drawable/app_icon -->
<meta-data android:name="SWRVE_PUSH_ICON" android:resource="@drawable/ic_launcher"/>
<meta-data android:name="SWRVE_PUSH_ICON_MATERIAL" android:resource="@drawable/ic_launcher_material"/>
<meta-data android:name="SWRVE_PUSH_ICON_LARGE" android:resource="@drawable/ic_launcher_large" />
<meta-data android:name="SWRVE_PUSH_ACCENT_COLOR" android:resource="@android:color/black" />

<!-- This is a reference to the activity to open when the push is followed. The Unity default is
     com.unity3d.player.UnityPlayerNativeActivity -->
<meta-data android:name="SWRVE_PUSH_ACTIVITY" android:value=".MainActivity"/>
<meta-data android:name="SWRVE_PUSH_TITLE" android:value="Your app title"/>

<!-- Add entries for Swrve receiver and intent service -->
<receiver android:name="com.google.android.gms.gcm.GcmReceiver" 
		  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="YOUR_PACKAGE_NAME" />
  </intent-filter>
</receiver>
<service android:name="com.kongregate.android.api.swrve.KongSwrveGcmIntentService">
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  </intent-filter>
</service>
<service
  android:name="com.swrve.sdk.gcm.SwrveGcmInstanceIDListenerService"
  android:exported="false" >
  <intent-filter>
    <action android:name="com.google.android.gms.iid.InstanceID" />
  </intent-filter>
</service>

<!-- The SwrveWakefulReceiver will automatically be pulled in for Gradle builds. For Library
     project and Unity plugin builds you will need to add the following to your manifest.
     Replace ${applicationId} with your package name -->
<receiver android:exported="false" android:name="com.swrve.sdk.SwrveWakefulReceiver">
    <intent-filter>
        <action android:name="${applicationId}.swrve.SwrveWakeful" />
    </intent-filter>
</receiver>

Android Example

Map<String,Object> apiOptions = new HashMap<String,Object>();
apiOptions.put(KongregateAPI.KONGREGATE_SWRVE_SENDER_ID, "YOUR_SENDER_ID");
... // set other API options
APIBootstrap.initializeNativeAPI(activity, gameId, apiKey, apiOptions);

Unity Example

KongregateAPI.Settings.SwrveConfig = new Dictionary<string,object>() {
  { KongregateAPI.KONGREGATE_SWRVE_SENDER_ID, "YOUR_SENDER_ID" },
};
... // set other API options
KongregateAPI.Initialize(gameId, apiKey);

Air Example

KongregateAPI.settings.swrveConfig = {
  "senderId": "648571852960"
};
... // set other API options
KongregateAPI.initialize(root.stage, gameId, apiKey);

Testing

To verify everything is working properly, use the Swrve QA Devices and the Swrve Dashboard to send some test push notifications to yourself.