Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yordan-ne committed Aug 18, 2017
2 parents 2eff296 + 10b4f26 commit cabf02e
Show file tree
Hide file tree
Showing 507 changed files with 491 additions and 53,844 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Project
############################
ios/demo/depends
cordova/sample/plugins
cordova/sample/platforms
cordova/sample/node_modules

############################
# MAC OS X
Expand Down
1 change: 1 addition & 0 deletions android/sample/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/sample/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions android/sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def getDate() {
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.syniverse.scg.push-sdk:scg-push-sdk-android:1.0'
// compile 'com.syniverse.scg.push-sdk:scg-push-sdk-android:1.1'
// Only for development
// compile project(':sdk')
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile project(':sdk')
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'me.leolin:ShortcutBadger:1.1.13@aar'
// --- END SDK and it's dependencies ---
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
Expand All @@ -66,4 +66,3 @@ dependencies {
}

apply plugin: 'com.google.gms.google-services'

Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ private void init(String url, String appId, String auth) {

public void onTokenRegister(final View view) {
final String token = pushToken.getText().toString();
System.out.println("!!!! token: " + token);

if (!TextUtils.isEmpty(token)) {
ScgClient.getInstance().registerPushToken(token, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void onMessageReceived(final String messageId, final ScgMessage messag
deliveryReport(messageId);
if (message.isInbox()) {
return;
};
}

final String msg = message.getBody();

Expand Down
2 changes: 1 addition & 1 deletion android/sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions android/sample/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include ':app'
//include ":sdk"
//project(":sdk").projectDir = file("../sdk/lib")
include ":sdk"
project(":sdk").projectDir = file("../sdk/lib")
1 change: 1 addition & 0 deletions android/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildscript {

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}

Expand Down
7 changes: 5 additions & 2 deletions android/sdk/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ publishing {
dependencies {
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile 'com.google.firebase:firebase-messaging:9.8.0'

// Required for local unit tests (JUnit 4 framework)
testCompile 'junit:junit:4.12'
Expand All @@ -84,7 +84,10 @@ group = mavenGroup
version = mavenVersion

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def propFile = project.rootProject.file('local.properties')
if (propFile.exists()) {
properties.load(propFile.newDataInputStream())
}

bintray {
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : properties.getProperty("bintrayUser")
Expand Down
4 changes: 2 additions & 2 deletions android/sdk/lib/publish-constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {
bintraySiteUrl = 'https://developer.syniverse.com'
bintrayGitUrl = 'https://github.com/Syniverse/Push-Notification-SDK.git'

mavenVersion = '1.0'
mavenVersion = '1.1'
mavenGroup = 'com.syniverse.scg.push-sdk'
mavenArtifact = 'scg-push-sdk-android'

Expand All @@ -13,4 +13,4 @@ ext {
bintrayLicense = 'MIT'

bintrayUserOrg = 'scg'
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.syniverse.scg.push.sdk;

import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import com.google.firebase.messaging.RemoteMessage;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;
import java.util.Set;

/**
* Created by lekov on 11/17/16.
Expand All @@ -29,8 +34,11 @@ static ScgMessage from(RemoteMessage message) {
return new ScgMessage(message);
}

static ScgMessage from(Bundle message) {
return new ScgMessage(message);
static public ScgMessage from(Bundle message) {
if (message.containsKey(MESSAGE_ID)) {
return new ScgMessage(message);
}
return null;
}

private ScgMessage(RemoteMessage message) {
Expand Down Expand Up @@ -162,6 +170,24 @@ public String toString() {
return data.toString();
}

public JSONObject toJson() {
JSONObject json = new JSONObject();
Set<String> keys = data.keySet();
for (String key : keys) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
json.put(key, JSONObject.wrap(data.get(key)));
} else {
json.put(key, data.get(key));
}
} catch(JSONException e) {
return null;
}
}

return json;
}

@Override
public int describeContents() {
return 0;
Expand Down
189 changes: 189 additions & 0 deletions cordova/plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
SCG Push SDK - Cordova
===

This is the SCG Push SDK for Cordova. It is distributed as a plugin. The platforms supported are Android and iOS.

# SDK Usage

## Install

Add the plugin to your project:

```
cordova plugin add @syniverse/cordova-plugin-scg-push
```

Download your Firebase configuration file for Android (google-services.json) and place it in the root folder of your cordova application.

## Initialize

Call the `start` method of the plugin to initialize it:

```
scg.push.start(accessToken, appId, callbackUri, function() {
console.log('ok start');
}, function(error) {
console.error('error start ' + error);
});
```

The parameters are:

Param | Description
-- | --
accessToken | Access token to authenticate
appId | Application Id
callbackUri | The URL of the SCG REST service
success | The callback function for the successful operation
failure | The callback function for the failed operation

## Get the Push Token (Android only)

To get the application specific push token:

```
scg.push.getToken(function(token) {
// use the token to register it
console.log('ok getToken ' + token);
}, function(error) {
console.error('error getToken ' + error);
});
```
**Note**: for iOS this method will return an empty string (`''`).

## Register Push token

To register the push token call:

```
scg.push.registerPushToken(pushToken, function(result) {
console.log('ok registerPushToken ');
}, function(error) {
console.error('error registerPushToken: ' + error);
});
```

## Unregister Push token
To stop receiving SCG messages call unregisterPushToken :

```
scg.push.unregisterPushToken(pushToken, function(result) {
console.log('ok unregisterPushToken ');
}, function(error) {
console.error('error unregisterPushToken: ' + error);
});
```

## Register callback to receive SCG messages (Android Only)
```
scg.push.onNotification(function(scgMessage) {
console.log('ok onNotification ' + JSON.stringify(data));
}, function (error) {});
```

### Receiving a notification flow:
- The application is in foreground: the notification (the SCG message) is received in the callback
- The application is in background:
- The message notification type is **os** ("push:notify_type":"os"): after the user click on the notification and the application registers the callback for the messages, the callback will be called with the message data;
- The message notification type is **silent** or **app**: after the application registers the callback it will receive the message (the callback will be called) .

## Register callback for the token changes (Android only)
To register for Firebase token change notifications:
```
scg.push.onTokenRefresh(function(newToken) {
console.log('ok onNewToken ' + newToken);
}, function() {});
```

## Report message status
```
scg.push.reportStatus(messageId, messageState, function(data) {
console.log('ok reportStatus ' + JSON.stringify(data));
}, function (error) {
console.log('error reportStatus ' + JSON.stringify(error));
});
```

Where `messageId` is the id of the message.
And `messageState` can one of the following:
- DELIVERED,
- MEDIA_REQUESTED,
- READ,
- CLICKTHRU,
- CONVERTED.

## Resolve tracked link
```
scg.push.resolveTrackedLink(message['deep_link'], function(data) {
console.log('ok resolveTrackedLink ' + JSON.stringify(data));
}, function (error) {
console.log('error resolveTrackedLink ' + JSON.stringify(error));
});
```

## Download a message attachment
If the message contains an attachment it can be download:
```
scg.push.loadAttachment(message['scg-message-id'], message['scg-attachment-id'], function(data) {
console.log('ok loadAttachment ' + JSON.stringify(data));
}, function (error) {
console.log('error loadAttachment ' + JSON.stringify(error));
});
```

The `data` in the success callback contains the mimeType of the attachment and local URI of the downloaded file.

## Reset badge count
```
scg.push.resetBadge(pushToken, function(data) {
console.log('ok resetBadge ' + JSON.stringify(data));
}, function (error) {
console.log('error resetBadge ' + JSON.stringify(error));
});
```

Where `pushToken` is the registered token.

## Delete all inbox messages
All messages stored in the inbox can be deleted:

```
scg.push.deleteAllInboxMessages();
```

## Delete an inbox message by message id
```
scg.push.deleteInboxMessage(message['scg-message-id']);
```

## Delete an inbox message by index

```
scg.push.deleteInboxMessageAtIndex(0);
```

## Get all inbox messages
```
scg.push.getAllInboxMessages(function(data) {
console.log('ok getAllInboxMessages ' + JSON.stringify(data));
});
```

## Get inbox message at index

```
scg.push.getInboxMessageAtIndex(0, function(message) {
console.log('ok getInboxMessageAtIndex ' + JSON.stringify(message));
}, function (error) {
console.log('error getInboxMessageAtIndex ');
});
```

## Get inbox messages count

```
scg.push.getInboxMessagesCount(function(count) {
console.log('ok getInboxMessagesCount ' + count);
});
```
2 changes: 1 addition & 1 deletion cordova/plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@syniverse/cordova-plugin-scg-push",
"version": "1.0.1",
"version": "1.0.3",
"description": "SCG Push Notification SDK Cordova Plugin",
"types": "./types/index.d.ts",
"cordova": {
Expand Down
6 changes: 3 additions & 3 deletions cordova/plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<framework src="com.google.code.gson:gson:2.8.0" />
<framework src="com.squareup.retrofit2:retrofit:2.3.0" />
<framework src="com.squareup.retrofit2:converter-gson:2.3.0" />
<framework src="com.syniverse.scg.push-sdk:scg-push-sdk-android:1.0" />
<framework src="com.syniverse.scg.push-sdk:scg-push-sdk-android:1.1" />
<framework src="src/android/scg-build.gradle" custom="true" type="gradleReference" />
<source-file src="src/android/com/syniverse/scg/push/CordovaScgClient.java" target-dir="src/com/syniverse/scg/push" />
<source-file src="src/android/com/syniverse/scg/push/cordova/sample/MainReceiver.java" target-dir="src/com/syniverse/scg/push/cordova/sample" />
<source-file src="src/android/com/syniverse/scg/push/MainReceiver.java" target-dir="src/com/syniverse/scg/push" />

<config-file target="res/xml/config.xml" parent="/*">
<feature name="ScgPush">
Expand All @@ -41,7 +41,7 @@
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<receiver android:enabled="true" android:exported="false" android:name=".MainReceiver">
<receiver android:enabled="true" android:exported="false" android:name="com.syniverse.scg.push.MainReceiver">
<intent-filter>
<action android:name="com.syniverse.scg.push.sdk.action.PUSH_TOKEN_RECEIVED" />
<action android:name="com.syniverse.scg.push.sdk.action.MESSAGE_RECEIVED" />
Expand Down
Loading

0 comments on commit cabf02e

Please sign in to comment.