Skip to content

Commit

Permalink
Merge pull request #140 from ably/feature/push-notifications
Browse files Browse the repository at this point in the history
Push notifications (activation and subscription)
  • Loading branch information
QuintinWillison authored Aug 28, 2021
2 parents 4ed6c09 + 320cc4b commit b30e3b7
Show file tree
Hide file tree
Showing 115 changed files with 4,632 additions and 448 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
device:
- 'iPhone 12' # we are not specifying the iOS version as it tends to change
fail-fast: false
runs-on: 'macos-latest'
runs-on: 'macos-11'
steps:
- name: 'List Simulators'
run: 'xcrun instruments -s'
Expand Down
4 changes: 2 additions & 2 deletions .run/example.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="example" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--observatory-port 8888 --disable-service-auth-codes" />
<configuration default="false" name="Example App (Duplicate and modify)" type="FlutterRunConfigurationType" factoryName="Flutter">
<option name="additionalArgs" value="--observatory-port 8888 --disable-service-auth-codes --dart-define=ABLY_API_KEY=replace_with_your_api_key" />
<option name="filePath" value="$PROJECT_DIR$/example/lib/main.dart" />
<method v="2" />
</configuration>
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ You may also find it insightful to run the following command, as it can reveal i

flutter doctor

If using Android Studio, delete the `.packages` file. It is a deprecated autogenerated file which confuses Android Studio into thinking all files are build outputs instead of source files.

## Implementation Notes

### Interfaces
Expand Down Expand Up @@ -55,6 +57,12 @@ got both iOS and Android emulators open:

flutter run -d all

## Debugging notes (Android Studio)

To debug both platform and Dart code simultaneously:
- In Android: in the Flutter project window, launch the application in debug mode in Android Studio. Then, in the Android project window, attach the debugger to the Android process.
- In iOS: In the Flutter project window, launch the application in debug mode in Android Studio. Then, in Xcode, on the menu bar, click `Debug` > `Attach to Process` > `Runner`.

## Helpful Resources

- Flutter
Expand Down Expand Up @@ -209,6 +217,7 @@ The release process must include the following steps:
9. Execute `flutter pub publish` from the root of this repository
10. Create a tag named like `v1.2.3`, using `git tag v1.2.3`
11. Push the newly created tag to GitHub: `git push origin v1.2.3`
12. Create a release on GitHub following the [previous releases]((https://github.com/ably/ably-flutter/releases)) as examples.

To check that everything is looking sensible to the Flutter tools, without publishing, you can use:

Expand Down
344 changes: 344 additions & 0 deletions PushNotifications.md

Large diffs are not rendered by default.

41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ We handle the complexity of realtime messaging so you can focus on your code.

### iOS

iOS 9 or newer.
iOS 10 or newer.

### Android

Expand All @@ -46,7 +46,6 @@ Features that we do not currently support, but we do plan to add in the future:
- Symmetric encryption ([#104](https://github.com/ably/ably-flutter/issues/104))
- Ably token generation ([#105](https://github.com/ably/ably-flutter/issues/105))
- REST and Realtime Stats ([#106](https://github.com/ably/ably-flutter/issues/106))
- Push Notifications target ([#107](https://github.com/ably/ably-flutter/issues/107))
- Custom transportParams ([#108](https://github.com/ably/ably-flutter/issues/108))
- Push Notifications Admin ([#109](https://github.com/ably/ably-flutter/issues/109))
- Remember fallback host during failures ([#47](https://github.com/ably/ably-flutter/issues/47))
Expand All @@ -55,10 +54,36 @@ Features that we do not currently support, but we do plan to add in the future:

### Running example app

- Clone the repo
- cd to `example` folder
- run `flutter pub get` to install dependencies
- `flutter run` will start the application on connected android / iOS device
- To run the example app, you need an Ably API key. Create a free account on [ably.com](https://ably.com/) and then use your API key from there in the example app.
- Clone the project

#### Android Studio / IntelliJ Idea

Under the run/ debug configuration drop down menu, click `Edit Configurations...`. Duplicate the `Example App (Duplicate and modify)` configuration. Leave the "Store as project file" unchecked to avoid committing your Ably API key into a repository. Update this new run configuration's `additional run args` with your ably API key. Run or debug the your new run/ debug configuration.

![run-configuration-1](images/run-configuration-1.png)

![run-configuration-2](images/run-configuration-2.png)

#### Visual Studio Code

- Under `Run and Debug`,
- Select the gear icon to view `launch.json`
- Add your Ably API key to the `configurations.args`, i.e. replace `replace_with_your_api_key` with your own Ably API key.
- To choose a specific device when more than one are connected: to launch on a specific device, make sure it is the only device plugged in. To run on a specific device when you have multiple plugged in, add another element to the `configuration.args` value, with `--device-id=replace_with_device_id`
- Make sure to replace `replace_with_your_device` with your device ID from `flutter devices`
- select the `example` configuration

#### Command Line using the Flutter Tool

- Change into the example app directory: `cd example`
- Install dependencies: `flutter pub get`
- Launch the application: `flutter run --dart-define ABLY_API_KEY=put_your_ably_api_key_here`, remembering to replace `put_your_ably_api_key_here` with your own API key.
- To choose a specific device when more than one are connected: get your device ID using `flutter devices`, and then running `flutter run --dart-define=ABLY_API_KEY=put_your_ably_api_key_here --device-id replace_with_device_id`

### Push Notifications

See [PushNotifications.md](PushNotifications.md) for detailed information on getting PN working with the example app.

### Troubleshooting

Expand Down Expand Up @@ -493,6 +518,10 @@ channel
);
```

### Push Notifications

See [PushNotifications.md](PushNotifications.md) for detailed information on using PN with this plugin.

## Caveats

### RTE6a compliance
Expand Down
11 changes: 6 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ version '1.0'
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.1.3'
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

apply plugin: 'com.android.library'

dependencies {
implementation 'io.ably:ably-android:1.2.6'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'
api 'io.ably:ably-android:1.2.7'
api 'com.google.firebase:firebase-messaging:22.0.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}

android {
Expand Down
Binary file added android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
160 changes: 160 additions & 0 deletions android/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env bash

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
echo "$*"
}

die ( ) {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
Loading

0 comments on commit b30e3b7

Please sign in to comment.