Skip to content

Commit

Permalink
Merge pull request #58 from jvandijk/feature/ti-7.x-compatibility
Browse files Browse the repository at this point in the history
Titanium 7.x compatibility
  • Loading branch information
jvandijk authored Feb 4, 2018
2 parents b827cec + c834c39 commit dd250e2
Show file tree
Hide file tree
Showing 25 changed files with 192 additions and 115 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ build
Plafile.yml
build.properties
libs
*/dist/modules
dist
*.xcuserdatad
node_modules
java-sources.txt
com.williamrijksen.onesignal-*.zip
21 changes: 11 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode8.3
osx_image: xcode9.2

env:
global:
Expand All @@ -8,33 +8,35 @@ env:
cache:
directories:
- node_modules
- $HOME/android-ndk-r11c
- $HOME/android-sdk
- $HOME/Library/Caches/Homebrew
- $HOME/Library/Application Support/Titanium
- $HOME/Library/Application\ Support/Titanium
timeout: 600

before_install:
- MODULE_ROOT=$PWD
- brew update
- brew update > /dev/null
- brew install nvm
- nvm install 4
- nvm install v6.12.3
- npm config delete prefix
- nvm use --delete-prefix v4.8.4 4
- nvm use v6.12.3
- brew cask uninstall oclint
- brew tap oclint/formulae
- brew install oclint
- oclint -version

install:
- cd $MODULE_ROOT
- curl -o install.sh https://rawcdn.githack.com/sgtcoolguy/ci/v8/travis/install.sh
- source install.sh -s "--branch 6_1_X"
- curl -o install.sh https://raw.githubusercontent.com/jvandijk/ci/master/travis/install.sh
- source install.sh -s "--branch 7_0_X" -a 25

before_script:
- curl -o script.sh https://rawcdn.githack.com/sgtcoolguy/ci/v8/travis/script.sh
- curl -o script.sh https://raw.githubusercontent.com/hansemannn/ci/master/travis/script.sh
- chmod +x script.sh

script:
- MODULE_ROOT=$MODULE_ROOT bash script.sh
- cd $MODULE_ROOT
- sh -c 'cd ios && xcodebuild -dry-run | tee xcodebuild.log && oclint-xcodebuild && oclint-json-compilation-database'

deploy:
Expand All @@ -48,4 +50,3 @@ deploy:
on:
repo: williamrijksen/com.williamrijksen.onesignal
tags: true

18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Before setting up the Titanium SDK, you must generate the appropriate credential

```xml
<modules>
<module platform="iphone" version="1.7.1">com.williamrijksen.onesignal</module>
<module platform="android" version="1.7.1">com.williamrijksen.onesignal</module>
<module platform="iphone" version="2.0.0">com.williamrijksen.onesignal</module>
<module platform="android" version="2.0.0">com.williamrijksen.onesignal</module>
</modules>
```
1. Configure your app into the App Settings panel for the right Platform (Android and/or iOS).
Expand Down Expand Up @@ -154,18 +154,24 @@ Cheers!
If you already have Titanium installed, skip the first 2 steps, if not let's install Titanium locally.
1. `brew install yarn --without-node` to install yarn without relying on a specific Node version
1. In the ios directory execute `yarn install`
1. In the root directory execute `yarn install`
1. Step into the ios directory
1. Alter the `titanium.xcconfig` to build with the preferred SDK
1. To build the module execute `rm -rf build && ./node_modules/.bin/ti build -p ios --build-only`
1. To build the module execute `rm -rf build && ../node_modules/.bin/ti build -p ios --build-only`
### Android
1. `brew install yarn --without-node` to install yarn without relying on a specific Node version
1. In the root directory execute `yarn install`
1. Step into the android directory
1. Copy `build.properties.dist` to `build.properties` and edit to match your environment
1. To build the module execute `rm -rf build && mkdir -p build/docs && ant`
1. To build the module execute `rm -rf build && mkdir -p build/docs && ../node_modules/.bin/ti build -p android --build-only`
#### Google Play Services
If for some reason you need to change the used Google Play Services version, execute the following actions:
Since Titanium 7.x this module relies on [https://github.com/appcelerator-modules/ti.playservices](ti.playservices)
If you still need to support Titanium 6.x and you need to change the used Google Play Services version, execute the following actions:
1. Install the Google Play Services on your system:
```bash
Expand Down
10 changes: 5 additions & 5 deletions android/build.properties.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
titanium.sdk=<YOUR_HOMEPATH>/Library/Application\ Support/Titanium/
titanium.os=osx
titanium.version=6.1.2.GA
android.sdk=/usr/local/share/android-sdk
android.ndk=/usr/local/share/android-sdk/ndk-bundle
titanium.version=7.0.2.v20180124150631
android.sdk=<YOUR_HOMEPATH>/android-sdk
android.ndk=<YOUR_HOMEPATH>/android-sdk/ndk-bundle

titanium.platform=${titanium.sdk}/mobilesdk/${titanium.os}/${titanium.version}/android
android.platform=${android.sdk}/platforms/android-23
google.apis=${android.sdk}/add-ons/addon-google_apis-google-23
android.platform=${android.sdk}/platforms/android-25
google.apis=${android.sdk}/add-ons/addon-google_apis-google-25
Binary file modified android/lib/OneSignalSDK.jar
Binary file not shown.
Binary file removed android/lib/google-play-services-base.jar
Binary file not shown.
Binary file removed android/lib/google-play-services-basement.jar
Binary file not shown.
Binary file removed android/lib/google-play-services-gcm.jar
Binary file not shown.
Binary file removed android/lib/google-play-services-idd.jar
Binary file not shown.
Binary file removed android/lib/google-play-services-location.jar
Binary file not shown.
13 changes: 7 additions & 6 deletions android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.7.1
apiversion: 3
architectures: armeabi-v7a x86
#

version: 2.0.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
description: com.williamrijksen.onesignal
author: William Rijksen
license: Specify your license
copyright: Copyright (c) 2017 by William Rijksen
copyright: Copyright (c) 2018 by William Rijksen

# these should not be edited
name: com.williamrijksen.onesignal
moduleid: com.williamrijksen.onesignal
guid: 67065763-fd5e-4069-a877-6c7fd328f877
platform: android
minsdk: 6.0.0.GA
respackage: com.google.android.gms
minsdk: 7.0.1.GA
1 change: 0 additions & 1 deletion android/respackageinfo

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;
import org.appcelerator.titanium.TiApplication;
Expand All @@ -28,6 +29,14 @@ public class ComWilliamrijksenOnesignalModule extends KrollModule
private static ComWilliamrijksenOnesignalModule module;
private static OSNotificationOpenResult openNotification;

public static final OneSignal.LOG_LEVEL LOG_LEVEL_NONE = OneSignal.LOG_LEVEL.NONE;
public static final OneSignal.LOG_LEVEL LOG_LEVEL_DEBUG = OneSignal.LOG_LEVEL.DEBUG;
public static final OneSignal.LOG_LEVEL LOG_LEVEL_INFO = OneSignal.LOG_LEVEL.INFO;
public static final OneSignal.LOG_LEVEL LOG_LEVEL_WARN = OneSignal.LOG_LEVEL.WARN;
public static final OneSignal.LOG_LEVEL LOG_LEVEL_ERROR = OneSignal.LOG_LEVEL.ERROR;
public static final OneSignal.LOG_LEVEL LOG_LEVEL_FATAL = OneSignal.LOG_LEVEL.FATAL;
public static final OneSignal.LOG_LEVEL LOG_LEVEL_VERBOSE = OneSignal.LOG_LEVEL.VERBOSE;

public ComWilliamrijksenOnesignalModule()
{
super();
Expand All @@ -51,6 +60,7 @@ public static void onAppCreate(TiApplication app)
.startInit(TiApplication.getInstance())
.setNotificationReceivedHandler(new NotificationReceivedHandler())
.setNotificationOpenedHandler(new NotificationOpenedHandler())
.unsubscribeWhenNotificationsAreDisabled(true)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
.init();
}
Expand All @@ -61,8 +71,11 @@ public void listenerAdded(String type, int count, KrollProxy proxy)
if (type.equals("notificationOpened") && count == 1 && openNotification instanceof OSNotificationOpenResult) {
Log.d(LCAT,"com.williamrijksen.onesignal fire delayed event");
try {
OSNotificationPayload payload = openNotification.notification.payload;
proxy.fireEvent("notificationOpened", payload.toJSONObject());
if (openNotification.notification.payload != null) {
JSONObject payload = openNotification.notification.payload.toJSONObject();
payload.put("foreground", openNotification.notification.isAppInFocus);
proxy.fireEvent("notificationOpened", payload);
}
} catch (Throwable t) {
Log.d(LCAT, "com.williamrijksen.onesignal OSNotificationOpenResult could not be converted to JSON");
}
Expand All @@ -87,6 +100,12 @@ public void deleteTag(Object tag)
OneSignal.deleteTag(key);
}

@Kroll.method
public void setSubscription(boolean enable)
{
OneSignal.setSubscription(enable);
}

@Kroll.method
public void getTags(KrollFunction handler)
{
Expand All @@ -101,6 +120,24 @@ public void idsAvailable(KrollFunction handler)
OneSignal.idsAvailable(new IdsAvailableHandler());
}

@Kroll.method
public void setLogLevel(HashMap args)
{
OneSignal.LOG_LEVEL logLevel = LOG_LEVEL_NONE;
OneSignal.LOG_LEVEL visualLevel = LOG_LEVEL_NONE;

Object level = args.get("logLevel");
if (level instanceof OneSignal.LOG_LEVEL) {
logLevel = (OneSignal.LOG_LEVEL) level;
}

level = args.get("visualLevel");
if (level instanceof OneSignal.LOG_LEVEL) {
visualLevel = (OneSignal.LOG_LEVEL) level;
}
OneSignal.setLogLevel(logLevel, visualLevel);
}

private class GetTagsHandler implements OneSignal.GetTagsHandler
{
@Override
Expand Down Expand Up @@ -146,12 +183,18 @@ private static class NotificationOpenedHandler implements OneSignal.Notification
public void notificationOpened(OSNotificationOpenResult result)
{
Log.d(LCAT, "com.williamrijksen.onesignal Notification opened handler");
if (getModuleInstance() != null) {
if (TiApplication.getAppCurrentActivity() != null && getModuleInstance() != null) {
try {
OSNotificationPayload payload = result.notification.payload;

if (getModuleInstance().hasListeners("notificationOpened") && payload != null) {
getModuleInstance().fireEvent("notificationOpened", payload.toJSONObject());
if (result.notification.payload != null) {
JSONObject payload = result.notification.payload.toJSONObject();
payload.put("foreground", result.notification.isAppInFocus);

if (getModuleInstance().hasListeners("notificationOpened")) {
getModuleInstance().fireEvent("notificationOpened", payload);
} else {
// save the notification for later processing
openNotification = result;
}
}
} catch (Throwable t) {
Log.d(LCAT, "com.williamrijksen.onesignal OSNotificationOpenResult could not be converted to JSON");
Expand All @@ -169,12 +212,15 @@ private static class NotificationReceivedHandler implements OneSignal.Notificati
public void notificationReceived(OSNotification notification)
{
Log.d(LCAT, "com.williamrijksen.onesignal Notification received handler");
if (getModuleInstance() != null) {
if (TiApplication.getAppCurrentActivity() != null && getModuleInstance() != null) {
try {
OSNotificationPayload payload = notification.payload;
if (notification.payload != null) {
JSONObject payload = notification.payload.toJSONObject();
payload.put("foreground", notification.isAppInFocus);

if (getModuleInstance().hasListeners("notificationReceived") && payload != null) {
getModuleInstance().fireEvent("notificationReceived", payload.toJSONObject());
if (getModuleInstance().hasListeners("notificationReceived")) {
getModuleInstance().fireEvent("notificationReceived", payload);
}
}
} catch (Throwable t) {
Log.d(LCAT, "com.williamrijksen.onesignal OSNotification could not be converted to JSON");
Expand Down
5 changes: 4 additions & 1 deletion android/timodule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@
</manifest>
</android>
<mobileweb></mobileweb>
</ti:module>
<modules>
<module platform="android">ti.playservices</module>
</modules>
</ti:module>
1 change: 1 addition & 0 deletions ios/Classes/ComWilliamrijksenOnesignalModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef void(^TagsResultHandler)(NSDictionary*, NSError*);

- (void)promptForPushNotificationsWithUserResponse:(id)args;
- (void)sendTag:(id)args;
- (void)setSubscription:(id)args;
- (void)deleteTag:(id)args;
- (void)getTags:(id)value;
- (void)setLogLevel:(id)args;
Expand Down
36 changes: 28 additions & 8 deletions ios/Classes/ComWilliamrijksenOnesignalModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,25 @@ + (void)load

- (void)_listenerAdded:(NSString*)type count:(int)count
{
NSLog(@"[DEBUG] com.williamrijksen.onesignal add listener %@", type);
if (count == 1 && [type isEqual:TiNotificationOpened]) {
NSDictionary* userInfo = [[[TiApp app] launchOptions] objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
OneSignalPayload *payload = [[OneSignalPayload alloc] initWithRawMessage:userInfo];
NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE cold boot TiNotificationOpened");
[self fireEvent:TiNotificationOpened withObject:[payload toDictionary]];
NSLog(@"[DEBUG] com.williamrijksen.onesignal add listener %@ count %i", type, count);

if (count == 1) {
if ([type isEqual:TiNotificationOpened]) {
NSLog(@"Notification opened handler added");
NSDictionary* userInfo = [[[TiApp app] launchOptions] objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
OneSignalPayload *payload = [[OneSignalPayload alloc] initWithRawMessage:userInfo];
NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE cold boot TiNotificationOpened");
[self fireEvent:TiNotificationOpened withObject:[payload toDictionary]];
}
} else if ([type isEqual:TiNotificationReceived]) {
NSLog(@"Notification received handler added");
NSDictionary* userInfo = [[[TiApp app] launchOptions] objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
OneSignalPayload *payload = [[OneSignalPayload alloc] initWithRawMessage:userInfo];
NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE TiNotificationReceived");
[self fireEvent:TiNotificationReceived withObject:[payload toDictionary]];
}
}
}
}
Expand All @@ -94,7 +106,7 @@ -(void)notificationReceived:(NSDictionary*)info
{
OneSignalPayload *payload = [[OneSignalPayload alloc] initWithRawMessage:info];

if ([self _hasListeners:TiNotificationReceived]) {
if ([self _hasListeners:TiNotificationReceived]) {
NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE TiNotificationReceived");
[self fireEvent:TiNotificationReceived withObject:[payload toDictionary]];
}
Expand Down Expand Up @@ -122,6 +134,14 @@ - (void)promptForPushNotificationsWithUserResponse:(id)args
}];
}

- (void)setSubscription:(id)arguments
{
id args = arguments;
ENSURE_UI_THREAD_1_ARG(args);
ENSURE_SINGLE_ARG(args, NSNumber);
[OneSignal setSubscription:[TiUtils boolValue:args]];
}

- (void)sendTag:(id)arguments
{
id args = arguments;
Expand Down
12 changes: 6 additions & 6 deletions ios/Classes/ComWilliamrijksenOnesignalModuleAssets.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

@implementation ComWilliamrijksenOnesignalModuleAssets

- (NSData*) moduleAsset
- (NSData *)moduleAsset
{

return nil;
return nil;
}

- (NSData*) resolveModuleAsset:(NSString*)path
- (NSData *)resolveModuleAsset:(NSString *)path
{

return nil;
return nil;
}

@end
2 changes: 1 addition & 1 deletion ios/Classes/OneSignalManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (OneSignalManager*)initWithNSNotification:(NSNotification *)notification
[self actionHandler:result.notification.payload.rawPayload];
};

id onesignalInitSettings = @{kOSSettingsKeyAutoPrompt : @NO};
id onesignalInitSettings = @{kOSSettingsKeyAutoPrompt : @NO, kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNone)};

NSDictionary *userInfo = [notification userInfo];
NSDictionary *launchOptions =
Expand Down
Loading

0 comments on commit dd250e2

Please sign in to comment.