diff --git a/.travis.yml b/.travis.yml
index 7614ca9..c609c47 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,5 @@
language: objective-c
-osx_image: xcode8.2
+osx_image: xcode8.3
env:
global:
@@ -18,7 +18,7 @@ before_install:
- brew install nvm
- nvm install 4
- npm config delete prefix
-- nvm use --delete-prefix v4.4.7 4
+- nvm use --delete-prefix v4.8.4 4
- brew cask uninstall oclint
- brew tap oclint/formulae
- brew install oclint
@@ -27,7 +27,7 @@ before_install:
install:
- cd $MODULE_ROOT
- curl -o install.sh https://rawcdn.githack.com/sgtcoolguy/ci/v8/travis/install.sh
-- source install.sh -s "--branch 6_0_X"
+- source install.sh -s "--branch 6_1_X"
before_script:
- curl -o script.sh https://rawcdn.githack.com/sgtcoolguy/ci/v8/travis/script.sh
diff --git a/README.md b/README.md
index 2669464..ffadad2 100644
--- a/README.md
+++ b/README.md
@@ -17,8 +17,8 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
```xml
- com.williamrijksen.onesignal
- com.williamrijksen.onesignal
+ com.williamrijksen.onesignal
+ com.williamrijksen.onesignal
```
1. Configure your app into the App Settings panel for the right Platform (Android and/or iOS).
@@ -46,9 +46,15 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
1. Register device for Push Notifications
```js
- // This registers your device automatically into OneSignal
+ // This registers your device automatically into OneSignal
var onesignal = require('com.williamrijksen.onesignal');
```
+1. On iOS you'll need to request permission to use notifications:
+ ```js
+ oneSignal.promptForPushNotificationsWithUserResponse(function(obj) {
+ alert(JSON.stringify(obj));
+ });
+ ```
1. To add the possibility to target people for notifications, send a tag:
```js
@@ -96,8 +102,10 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
visualLevel: onesignal.LOG_LEVEL_NONE
});
```
-1. Receive notifications callback: (does not work on iOS when the app is closed (swiped away). But works fine when the app is running on background)
- Opened:
+1. Opened listener:
+ The returned content is matching the available payload on OneSignal:
+ - [https://documentation.onesignal.com/docs/ios-native-sdk#section--osnotificationpayload-](iOS)
+ - [https://documentation.onesignal.com/docs/android-native-sdk#section--osnotificationpayload-](Android)
```js
onesignal.addEventListener('notificationOpened', function (evt) {
@@ -128,7 +136,10 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
});
```
-1. Received:
+1. Received listener:
+ The returned content is matching the available payload on OneSignal:
+ - [https://documentation.onesignal.com/docs/ios-native-sdk#section--osnotificationpayload-](iOS)
+ - [https://documentation.onesignal.com/docs/android-native-sdk#section--osnotificationpayload-](Android)
```js
onesignal.addEventListener('notificationReceived', function(evt) {
diff --git a/android/build.properties.dist b/android/build.properties.dist
new file mode 100644
index 0000000..0be38f4
--- /dev/null
+++ b/android/build.properties.dist
@@ -0,0 +1,9 @@
+titanium.sdk=/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.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
diff --git a/android/lib/OneSignalSDK.jar b/android/lib/OneSignalSDK.jar
index b085729..9bcfaa4 100755
Binary files a/android/lib/OneSignalSDK.jar and b/android/lib/OneSignalSDK.jar differ
diff --git a/android/manifest b/android/manifest
index d501ce7..d12c76c 100644
--- a/android/manifest
+++ b/android/manifest
@@ -2,13 +2,13 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
-version: 1.6.0
+version: 1.7.0
apiversion: 3
architectures: armeabi-v7a x86
description: com.williamrijksen.onesignal
author: William Rijksen
license: Specify your license
-copyright: Copyright (c) 2016 by William Rijksen
+copyright: Copyright (c) 2017 by William Rijksen
# these should not be edited
name: com.williamrijksen.onesignal
diff --git a/android/src/com/williamrijksen/onesignal/ComWilliamrijksenOnesignalModule.java b/android/src/com/williamrijksen/onesignal/ComWilliamrijksenOnesignalModule.java
index ffd4531..48ee42f 100644
--- a/android/src/com/williamrijksen/onesignal/ComWilliamrijksenOnesignalModule.java
+++ b/android/src/com/williamrijksen/onesignal/ComWilliamrijksenOnesignalModule.java
@@ -6,10 +6,12 @@
import com.onesignal.OSNotification;
import com.onesignal.OSNotificationAction;
import com.onesignal.OSNotificationOpenResult;
+import com.onesignal.OSNotificationPayload;
import java.util.HashMap;
import org.appcelerator.kroll.KrollModule;
+import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.common.Log;
@@ -23,48 +25,49 @@ public class ComWilliamrijksenOnesignalModule extends KrollModule
{
private static final String LCAT = "ComWilliamrijksenOnesignalModule";
private static final boolean DBG = TiConfig.LOGD;
- private boolean oneSignalInitDone;
+ private static ComWilliamrijksenOnesignalModule module;
+ private static OSNotificationOpenResult openNotification;
public ComWilliamrijksenOnesignalModule()
{
super();
- initOneSignal(TiApplication.getInstance().getCurrentActivity());
+ module = this;
}
- private void initOneSignal(Activity activity)
+ public static ComWilliamrijksenOnesignalModule getModuleInstance()
{
- if (activity == null || oneSignalInitDone) {
- return;
- }
-
- oneSignalInitDone = true;
-
- OneSignal
- .startInit(activity)
- .setNotificationReceivedHandler(new NotificationReceivedHandler())
- .setNotificationOpenedHandler(new NotificationOpenedHandler())
- .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
- .init();
+ return module;
}
- //TODO inFocusDisplaying should be configurable from Titanium App module initialization
- //variable to store the received call back function for the getTags method call
private KrollFunction getTagsCallback = null;
-
private KrollFunction idsAvailableCallback = null;
@Kroll.onAppCreate
public static void onAppCreate(TiApplication app)
{
- Log.d(LCAT, "inside onAppCreate");
+ Log.d(LCAT, "com.williamrijksen.onesignal inside onAppCreate");
+
+ OneSignal
+ .startInit(TiApplication.getInstance())
+ .setNotificationReceivedHandler(new NotificationReceivedHandler())
+ .setNotificationOpenedHandler(new NotificationOpenedHandler())
+ .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
+ .init();
}
- @Override
- public void onResume(Activity activity)
+ public void listenerAdded(String type, int count, KrollProxy proxy)
{
- super.onResume(activity);
- Log.d(LCAT, "Trying to initialize OneSignal if necessary");
- initOneSignal(activity);
+ Log.d(LCAT,"com.williamrijksen.onesignal added listener " + type);
+ 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());
+ } catch (Throwable t) {
+ Log.d(LCAT, "com.williamrijksen.onesignal OSNotificationOpenResult could not be converted to JSON");
+ }
+ openNotification = null;
+ }
}
@Kroll.method
@@ -98,9 +101,11 @@ public void idsAvailable(KrollFunction handler)
OneSignal.idsAvailable(new IdsAvailableHandler());
}
- private class GetTagsHandler implements OneSignal.GetTagsHandler {
+ private class GetTagsHandler implements OneSignal.GetTagsHandler
+ {
@Override
- public void tagsAvailable(JSONObject tags) {
+ public void tagsAvailable(JSONObject tags)
+ {
HashMap dict = new HashMap();
try {
dict.put("success", true);
@@ -117,7 +122,8 @@ public void tagsAvailable(JSONObject tags) {
}
}
- private class IdsAvailableHandler implements OneSignal.IdsAvailableHandler {
+ private class IdsAvailableHandler implements OneSignal.IdsAvailableHandler
+ {
@Override
public void idsAvailable(String userId, String registrationId)
{
@@ -133,49 +139,46 @@ public void idsAvailable(String userId, String registrationId)
}
}
- private class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
+ private static class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler
+ {
// This fires when a notification is opened by tapping on it.
@Override
- public void notificationOpened(OSNotificationOpenResult result) {
- try {
- JSONObject json = result.toJSONObject();
- HashMap kd = new HashMap();
-
- if (json.has("notification") && json.getJSONObject("notification").has("payload")) {
- JSONObject payload = json.getJSONObject("notification").getJSONObject("payload");
-
- if (payload.has("title")) {
- kd.put("title", payload.getString("title"));
- }
-
- if (payload.has("body")) {
- kd.put("body", payload.getString("body"));
- }
+ public void notificationOpened(OSNotificationOpenResult result)
+ {
+ Log.d(LCAT, "com.williamrijksen.onesignal Notification opened handler");
+ if (getModuleInstance() != null) {
+ try {
+ OSNotificationPayload payload = result.notification.payload;
- if (payload.has("additionlData")) {
- String additional = payload.getJSONObject("additionalData").toString();
- kd.put("additionalData", additional);
+ if (getModuleInstance().hasListeners("notificationOpened") && payload != null) {
+ getModuleInstance().fireEvent("notificationOpened", payload.toJSONObject());
}
+ } catch (Throwable t) {
+ Log.d(LCAT, "com.williamrijksen.onesignal OSNotificationOpenResult could not be converted to JSON");
}
- fireEvent("notificationOpened", kd);
- }
- catch (Throwable t) {
- Log.d(LCAT, "Notification result could not be converted to JSON");
+ } else {
+ // save the notification for later processing
+ openNotification = result;
}
}
}
- private class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
+ private static class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler
+ {
@Override
- public void notificationReceived(OSNotification notification) {
- JSONObject additionalData = notification.payload.additionalData;
- if(additionalData != null){
- String payload = additionalData.toString();
- HashMap kd = new HashMap();
- kd.put("additionalData", payload);
- fireEvent("notificationReceived", kd);
- }else{
- Log.d(LCAT, "No additionalData on notification payload =/");
+ public void notificationReceived(OSNotification notification)
+ {
+ Log.d(LCAT, "com.williamrijksen.onesignal Notification received handler");
+ if (getModuleInstance() != null) {
+ try {
+ OSNotificationPayload payload = notification.payload;
+
+ if (getModuleInstance().hasListeners("notificationReceived") && payload != null) {
+ getModuleInstance().fireEvent("notificationReceived", payload.toJSONObject());
+ }
+ } catch (Throwable t) {
+ Log.d(LCAT, "com.williamrijksen.onesignal OSNotification could not be converted to JSON");
+ }
}
}
}
diff --git a/ios/Classes/ComWilliamrijksenOnesignalModule.h b/ios/Classes/ComWilliamrijksenOnesignalModule.h
index a2f43fd..ef1ef43 100644
--- a/ios/Classes/ComWilliamrijksenOnesignalModule.h
+++ b/ios/Classes/ComWilliamrijksenOnesignalModule.h
@@ -7,11 +7,13 @@
#import "TiModule.h"
#import
+#import "OneSignalManager.h"
-@interface ComWilliamrijksenOnesignalModule : TiModule {}
+@interface ComWilliamrijksenOnesignalModule : TiModule {}
typedef void(^TagsResultHandler)(NSDictionary*, NSError*);
+- (void)promptForPushNotificationsWithUserResponse:(id)args;
- (void)sendTag:(id)args;
- (void)deleteTag:(id)args;
- (void)getTags:(id)value;
diff --git a/ios/Classes/ComWilliamrijksenOnesignalModule.m b/ios/Classes/ComWilliamrijksenOnesignalModule.m
index 0e1ffe0..137a21a 100644
--- a/ios/Classes/ComWilliamrijksenOnesignalModule.m
+++ b/ios/Classes/ComWilliamrijksenOnesignalModule.m
@@ -6,6 +6,7 @@
*/
#import "ComWilliamrijksenOnesignalModule.h"
+#import "OneSignalPayload.h"
#import "TiBase.h"
#import "TiHost.h"
#import "TiUtils.h"
@@ -13,98 +14,114 @@
@implementation ComWilliamrijksenOnesignalModule
+NSString * const TiNotificationReceived = @"notificationReceived";
+NSString * const TiNotificationOpened = @"notificationOpened";
+
+static OneSignalManager* _oneSignalManager = nil;
+
#pragma mark Internal
// this is generated for your module, please do not change it
--(id)moduleGUID
+- (id)moduleGUID
{
return @"67065763-fd5e-4069-a877-6c7fd328f877";
}
// this is generated for your module, please do not change it
--(NSString*)moduleId
+- (NSString*)moduleId
{
return @"com.williamrijksen.onesignal";
}
#pragma mark Lifecycle
-- (void) receivedHandler:(OSNotification *)notification {
- OSNotificationPayload* payload = notification.payload;
-
- NSString* title = @"";
- NSString* body = @"";
- NSDictionary* additionalData = [[NSDictionary alloc] init];
+- (void)startup
+{
+ [super startup];
- if(payload.title) {
- title = payload.title;
- }
+ [_oneSignalManager setDelegate:self];
+ NSLog(@"[INFO] started %@", self);
+}
- if (payload.body) {
- body = [payload.body copy];
- }
+-(void)shutdown:(id)sender
+{
+ _oneSignalManager = nil;
- if (payload.additionalData) {
- additionalData = payload.additionalData;
- }
+ [super shutdown:sender];
+}
- NSDictionary* notificationData = @{
- @"title": title,
- @"body": body,
- @"additionalData": additionalData
- };
- [self fireEvent:@"notificationReceived" withObject:notificationData];
-};
-
-- (void) actionHandler:(OSNotificationOpenedResult *)result {
- OSNotificationPayload* payload = result.notification.payload;
-
- NSString* title = @"";
- NSString* body = @"";
- NSDictionary* additionalData = [[NSDictionary alloc] init];
-
- if(payload.title) {
- title = payload.title;
++(void)initOneSignal:(NSNotification *)notification
+{
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal init initOnesignal?");
+ if (!_oneSignalManager) {
+ _oneSignalManager = [[OneSignalManager alloc] initWithNSNotification:notification];
}
+}
- if (payload.body) {
- body = [payload.body copy];
- }
++ (void)load
+{
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal load");
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initOneSignal:)
+ name:@"UIApplicationDidFinishLaunchingNotification" object:nil];
+}
- if (payload.additionalData) {
- additionalData = payload.additionalData;
+#pragma mark Listeners
+
+- (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]];
+ }
}
+}
- NSDictionary* notificationData = @{
- @"title": title,
- @"body": body,
- @"additionalData": additionalData};
- [self fireEvent:@"notificationOpened" withObject:notificationData];
+-(void)notificationOpened:(NSDictionary*)info
+{
+ OneSignalPayload *payload = [[OneSignalPayload alloc] initWithRawMessage:info];
+
+ if ([self _hasListeners:TiNotificationOpened]) {
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE TiNotificationOpened");
+ [self fireEvent:TiNotificationOpened withObject:[payload toDictionary]];
+ }
}
-- (void)startup
+-(void)notificationReceived:(NSDictionary*)info
{
- [super startup];
- [[TiApp app] setRemoteNotificationDelegate:self];
-
- NSString *OneSignalAppID = [[TiApp tiAppProperties] objectForKey:@"OneSignal_AppID"];
- [OneSignal initWithLaunchOptions:[[TiApp app] launchOptions]
- appId:OneSignalAppID
- handleNotificationReceived:^(OSNotification *notification) {
- [self receivedHandler:notification];
- }
- handleNotificationAction:^(OSNotificationOpenedResult *result) {
- [self actionHandler:result];
- }
- settings:@{
- kOSSettingsKeyInFocusDisplayOption: @(OSNotificationDisplayTypeNone),
- kOSSettingsKeyAutoPrompt: @YES}
- ];
- //TODO these settings should be configurable from the Titanium App on module initialization
+ OneSignalPayload *payload = [[OneSignalPayload alloc] initWithRawMessage:info];
+
+ if ([self _hasListeners:TiNotificationReceived]) {
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal FIRE TiNotificationReceived");
+ [self fireEvent:TiNotificationReceived withObject:[payload toDictionary]];
+ }
}
#pragma mark Public API's
+- (void)promptForPushNotificationsWithUserResponse:(id)args
+{
+ ENSURE_UI_THREAD(promptForPushNotificationsWithUserResponse, args);
+ ENSURE_SINGLE_ARG(args, KrollCallback);
+
+ if([args isKindOfClass:[KrollCallback class]]) {
+ [self replaceValue:args forKey:@"callback" notification:NO];
+ }
+
+ [OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal User accepted notifications: %d", accepted);
+ if ([args isKindOfClass:[KrollCallback class]]) {
+ NSDictionary* event = @{
+ @"accepted": NUMBOOL(accepted)
+ };
+ [self fireCallback:@"callback" withArg:event withSource:self];
+ }
+ }];
+}
+
- (void)sendTag:(id)arguments
{
id args = arguments;
diff --git a/ios/Classes/OneSignalDelegate.h b/ios/Classes/OneSignalDelegate.h
new file mode 100644
index 0000000..20fd090
--- /dev/null
+++ b/ios/Classes/OneSignalDelegate.h
@@ -0,0 +1,16 @@
+//
+// OneSignalDelegate.h
+// com.williamrijksen.onesignal
+//
+// Created by William Rijksen on 01-08-17.
+//
+//
+
+#import
+
+@protocol OneSignalDelegate
+
+-(void)notificationReceived:(NSDictionary*)info;
+-(void)notificationOpened:(NSDictionary*)info;
+
+@end
diff --git a/ios/Classes/OneSignalManager.h b/ios/Classes/OneSignalManager.h
new file mode 100644
index 0000000..2919b3a
--- /dev/null
+++ b/ios/Classes/OneSignalManager.h
@@ -0,0 +1,19 @@
+//
+// OneSignalManager.h
+// com.williamrijksen.onesignal
+//
+// Created by William Rijksen on 01-08-17.
+//
+//
+
+#import
+#import
+#import "OneSignalDelegate.h"
+
+@interface OneSignalManager : NSObject {}
+
+@property(assign, nonatomic) id delegate;
+
+- (OneSignalManager*)initWithNSNotification:(NSNotification*)notification;
+
+@end
diff --git a/ios/Classes/OneSignalManager.m b/ios/Classes/OneSignalManager.m
new file mode 100644
index 0000000..5fe9d5c
--- /dev/null
+++ b/ios/Classes/OneSignalManager.m
@@ -0,0 +1,55 @@
+//
+// OneSignalManager.m
+// com.williamrijksen.onesignal
+//
+// Created by William Rijksen on 01-08-17.
+//
+//
+
+#import "OneSignalManager.h"
+#import "TiApp.h"
+
+@implementation OneSignalManager {}
+
+- (void) receivedHandler:(NSDictionary *)rawPayload {
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal Result notification data %@", rawPayload);
+
+ [self.delegate notificationReceived:rawPayload];
+}
+
+- (void) actionHandler:(NSDictionary *)rawPayload {
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal Open notification data %@", rawPayload);
+
+ [self.delegate notificationOpened:rawPayload];
+}
+
+- (OneSignalManager*)initWithNSNotification:(NSNotification *)notification
+{
+ self = [super init];
+ if (self) {
+ NSLog(@"[DEBUG] com.williamrijksen.onesignal initWithLaunchOptions");
+
+ id notificationReceiverBlock = ^(OSNotification *notification) {
+ [self receivedHandler:notification.payload.rawPayload];
+ };
+
+ id notificationOpenedBlock = ^(OSNotificationOpenedResult *result) {
+ [self actionHandler:result.notification.payload.rawPayload];
+ };
+
+ id onesignalInitSettings = @{kOSSettingsKeyAutoPrompt : @NO};
+
+ NSDictionary *userInfo = [notification userInfo];
+ NSDictionary *launchOptions =
+ [userInfo valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
+ NSString *OneSignalAppID = [[TiApp tiAppProperties] objectForKey:@"OneSignal_AppID"];
+ [OneSignal initWithLaunchOptions:launchOptions
+ appId:OneSignalAppID
+ handleNotificationReceived:notificationReceiverBlock
+ handleNotificationAction:notificationOpenedBlock
+ settings:onesignalInitSettings];
+ }
+ return self;
+}
+
+@end
diff --git a/ios/Classes/OneSignalPayload.h b/ios/Classes/OneSignalPayload.h
new file mode 100644
index 0000000..6764d66
--- /dev/null
+++ b/ios/Classes/OneSignalPayload.h
@@ -0,0 +1,63 @@
+//
+// OneSignalPayload.h
+// com.williamrijksen.onesignal
+//
+// Created by Jeroen van Dijk on 08/08/2017.
+//
+//
+
+#import
+
+#ifndef OneSignalPayload_h
+#define OneSignalPayload_h
+
+/**
+ * This structure is a direct copy of https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignal.h#L83
+ *
+ */
+
+// #### Notification Payload Received Object
+
+@interface OneSignalPayload : NSObject
+
+/* Unique Message Identifier */
+@property(readonly)NSString* notificationID;
+
+/* Provide this key with a value of 1 to indicate that new content is available.
+ Including this key and value means that when your app is launched in the background or resumed application:didReceiveRemoteNotification:fetchCompletionHandler: is called. */
+@property(readonly)BOOL contentAvailable;
+
+/* The badge assigned to the application icon */
+@property(readonly)NSUInteger badge;
+
+/* The sound parameter passed to the notification
+ By default set to UILocalNotificationDefaultSoundName */
+@property(readonly)NSString* sound;
+
+/* Main push content */
+@property(readonly)NSString* title;
+@property(readonly)NSString* subtitle;
+@property(readonly)NSString* body;
+
+/* Web address to launch within the app via a UIWebView */
+@property(readonly)NSString* launchURL;
+
+/* Additional key value properties set within the payload */
+@property(readonly)NSDictionary* additionalData;
+
+/* iOS 10+ : Attachments sent as part of the rich notification */
+@property(readonly)NSDictionary* attachments;
+
+/* Action buttons passed */
+@property(readonly)NSArray *actionButtons;
+
+/* Holds the original payload received
+ Keep the raw value for users that would like to root the push */
+@property(readonly)NSDictionary *rawPayload;
+
+- (id)initWithRawMessage:(NSDictionary*)message;
+- (NSDictionary *)toDictionary;
+
+@end
+
+#endif /* OneSignalPayload_h */
diff --git a/ios/Classes/OneSignalPayload.m b/ios/Classes/OneSignalPayload.m
new file mode 100644
index 0000000..f80a5fb
--- /dev/null
+++ b/ios/Classes/OneSignalPayload.m
@@ -0,0 +1,151 @@
+//
+// OneSignalPayload.m
+// com.williamrijksen.onesignal
+//
+// Created by Jeroen van Dijk on 08/08/2017.
+//
+//
+
+#import "OneSignalPayload.h"
+#import
+
+@implementation OneSignalPayload
+@synthesize actionButtons = _actionButtons, additionalData = _additionalData, badge = _badge, body = _body, contentAvailable = _contentAvailable, notificationID = _notificationID, launchURL = _launchURL, rawPayload = _rawPayload, sound = _sound, subtitle = _subtitle, title = _title, attachments = _attachments;
+
+/**
+ * This method is a direct copy of https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m#L150
+ *
+ */
+- (id)initWithRawMessage:(NSDictionary*)message {
+ self = [super init];
+ if (self && message) {
+ _rawPayload = [NSDictionary dictionaryWithDictionary:message];
+
+ BOOL is2dot4Format = [_rawPayload[@"os_data"][@"buttons"] isKindOfClass:[NSArray class]];
+
+ if (_rawPayload[@"aps"][@"content-available"])
+ _contentAvailable = (BOOL)_rawPayload[@"aps"][@"content-available"];
+ else
+ _contentAvailable = NO;
+
+ if (_rawPayload[@"aps"][@"badge"])
+ _badge = [_rawPayload[@"aps"][@"badge"] intValue];
+ else
+ _badge = [_rawPayload[@"badge"] intValue];
+
+ _actionButtons = _rawPayload[@"o"];
+ if (!_actionButtons) {
+ if (is2dot4Format)
+ _actionButtons = _rawPayload[@"os_data"][@"buttons"];
+ else
+ _actionButtons = _rawPayload[@"os_data"][@"buttons"][@"o"];
+ }
+
+ if(_rawPayload[@"aps"][@"sound"])
+ _sound = _rawPayload[@"aps"][@"sound"];
+ else if(_rawPayload[@"s"])
+ _sound = _rawPayload[@"s"];
+ else if (!is2dot4Format)
+ _sound = _rawPayload[@"os_data"][@"buttons"][@"s"];
+
+ if(_rawPayload[@"custom"]) {
+ NSDictionary* custom = _rawPayload[@"custom"];
+ if (custom[@"a"])
+ _additionalData = [custom[@"a"] copy];
+ _notificationID = custom[@"i"];
+ _launchURL = custom[@"u"];
+
+ _attachments = [_rawPayload[@"at"] copy];
+ }
+ else if(_rawPayload[@"os_data"]) {
+ NSDictionary * os_data = _rawPayload[@"os_data"];
+
+ NSMutableDictionary *additional = [_rawPayload mutableCopy];
+ [additional removeObjectForKey:@"aps"];
+ [additional removeObjectForKey:@"os_data"];
+ _additionalData = [[NSDictionary alloc] initWithDictionary:additional];
+
+ _notificationID = os_data[@"i"];
+ _launchURL = os_data[@"u"];
+
+ if (is2dot4Format) {
+ if (os_data[@"att"])
+ _attachments = [os_data[@"att"] copy];
+ }
+ else {
+ if (os_data[@"buttons"][@"at"])
+ _attachments = [os_data[@"buttons"][@"at"] copy];
+ }
+ }
+
+ if(_rawPayload[@"m"]) {
+ id m = _rawPayload[@"m"];
+ if ([m isKindOfClass:[NSDictionary class]]) {
+ _body = m[@"body"];
+ _title = m[@"title"];
+ _subtitle = m[@"subtitle"];
+ }
+ else
+ _body = m;
+ }
+ else if(_rawPayload[@"aps"][@"alert"]) {
+ id a = message[@"aps"][@"alert"];
+ if ([a isKindOfClass:[NSDictionary class]]) {
+ _body = a[@"body"];
+ _title = a[@"title"];
+ _subtitle = a[@"subtitle"];
+ }
+ else
+ _body = a;
+ }
+ else if(_rawPayload[@"os_data"][@"buttons"][@"m"]) {
+ id m = _rawPayload[@"os_data"][@"buttons"][@"m"];
+ if ([m isKindOfClass:[NSDictionary class]]) {
+ _body = m[@"body"];
+ _title = m[@"title"];
+ _subtitle = m[@"subtitle"];
+ }
+ else
+ _body = m;
+ }
+ }
+
+ return self;
+}
+
+- (NSDictionary *)toDictionary
+{
+
+ unsigned int count = 0;
+
+ NSMutableDictionary *dictionary = [NSMutableDictionary new];
+ objc_property_t *properties = class_copyPropertyList([self class], &count);
+
+ for (int i = 0; i < count; i++) {
+
+ NSString *key = [NSString stringWithUTF8String:property_getName(properties[i])];
+ id value = [self valueForKey:key];
+
+ if (value == nil) {
+ // nothing todo
+ }
+ else if ([value isKindOfClass:[NSNumber class]]
+ || [value isKindOfClass:[NSString class]]
+ || [value isKindOfClass:[NSDictionary class]]) {
+ // TODO: extend to other types
+ [dictionary setObject:value forKey:key];
+ }
+ else if ([value isKindOfClass:[NSObject class]]) {
+ [dictionary setObject:[value toDictionary] forKey:key];
+ }
+ else {
+ NSLog(@"Invalid type for %@ (%@)", NSStringFromClass([self class]), key);
+ }
+ }
+
+ free(properties);
+
+ return dictionary;
+}
+
+@end
diff --git a/ios/com.williamrijksen.onesignal.xcodeproj/project.pbxproj b/ios/com.williamrijksen.onesignal.xcodeproj/project.pbxproj
index 4c36ce9..a26fb38 100644
--- a/ios/com.williamrijksen.onesignal.xcodeproj/project.pbxproj
+++ b/ios/com.williamrijksen.onesignal.xcodeproj/project.pbxproj
@@ -23,6 +23,11 @@
/* Begin PBXBuildFile section */
1F9396FF1EAF8ADB0076FF5A /* OneSignal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F9396FE1EAF8ADB0076FF5A /* OneSignal.framework */; };
+ 1FF036FA1F3499B4005DDE77 /* OneSignalDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FF036F71F3499B4005DDE77 /* OneSignalDelegate.h */; };
+ 1FF036FB1F3499B4005DDE77 /* OneSignalManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FF036F81F3499B4005DDE77 /* OneSignalManager.h */; };
+ 1FF036FC1F3499B4005DDE77 /* OneSignalManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FF036F91F3499B4005DDE77 /* OneSignalManager.m */; };
+ 1FF036FF1F3999E0005DDE77 /* OneSignalPayload.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FF036FE1F3999E0005DDE77 /* OneSignalPayload.m */; };
+ 1FF037011F399A03005DDE77 /* OneSignalPayload.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FF037001F399A03005DDE77 /* OneSignalPayload.h */; };
24DD6CF91134B3F500162E58 /* ComWilliamrijksenOnesignalModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 24DD6CF71134B3F500162E58 /* ComWilliamrijksenOnesignalModule.h */; };
24DD6CFA1134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 24DD6CF81134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m */; };
AA747D9F0F9514B9006C5449 /* ComWilliamrijksenOnesignal_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* ComWilliamrijksenOnesignal_Prefix.pch */; };
@@ -41,6 +46,11 @@
/* Begin PBXFileReference section */
1F9396FE1EAF8ADB0076FF5A /* OneSignal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OneSignal.framework; path = platform/OneSignal.framework; sourceTree = ""; };
+ 1FF036F71F3499B4005DDE77 /* OneSignalDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OneSignalDelegate.h; path = Classes/OneSignalDelegate.h; sourceTree = ""; };
+ 1FF036F81F3499B4005DDE77 /* OneSignalManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OneSignalManager.h; path = Classes/OneSignalManager.h; sourceTree = ""; };
+ 1FF036F91F3499B4005DDE77 /* OneSignalManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OneSignalManager.m; path = Classes/OneSignalManager.m; sourceTree = ""; };
+ 1FF036FE1F3999E0005DDE77 /* OneSignalPayload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OneSignalPayload.m; path = Classes/OneSignalPayload.m; sourceTree = ""; };
+ 1FF037001F399A03005DDE77 /* OneSignalPayload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OneSignalPayload.h; path = Classes/OneSignalPayload.h; sourceTree = ""; };
24DD6CF71134B3F500162E58 /* ComWilliamrijksenOnesignalModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ComWilliamrijksenOnesignalModule.h; path = Classes/ComWilliamrijksenOnesignalModule.h; sourceTree = ""; };
24DD6CF81134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ComWilliamrijksenOnesignalModule.m; path = Classes/ComWilliamrijksenOnesignalModule.m; sourceTree = ""; };
24DD6D1B1134B66800162E58 /* titanium.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = titanium.xcconfig; sourceTree = ""; };
@@ -95,6 +105,11 @@
children = (
24DD6CF71134B3F500162E58 /* ComWilliamrijksenOnesignalModule.h */,
24DD6CF81134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m */,
+ 1FF036F71F3499B4005DDE77 /* OneSignalDelegate.h */,
+ 1FF036F81F3499B4005DDE77 /* OneSignalManager.h */,
+ 1FF036F91F3499B4005DDE77 /* OneSignalManager.m */,
+ 1FF037001F399A03005DDE77 /* OneSignalPayload.h */,
+ 1FF036FE1F3999E0005DDE77 /* OneSignalPayload.m */,
);
name = Classes;
sourceTree = "";
@@ -116,7 +131,10 @@
buildActionMask = 2147483647;
files = (
AA747D9F0F9514B9006C5449 /* ComWilliamrijksenOnesignal_Prefix.pch in Headers */,
+ 1FF037011F399A03005DDE77 /* OneSignalPayload.h in Headers */,
24DD6CF91134B3F500162E58 /* ComWilliamrijksenOnesignalModule.h in Headers */,
+ 1FF036FA1F3499B4005DDE77 /* OneSignalDelegate.h in Headers */,
+ 1FF036FB1F3499B4005DDE77 /* OneSignalManager.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -190,6 +208,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 1FF036FF1F3999E0005DDE77 /* OneSignalPayload.m in Sources */,
+ 1FF036FC1F3499B4005DDE77 /* OneSignalManager.m in Sources */,
24DD6CFA1134B3F500162E58 /* ComWilliamrijksenOnesignalModule.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
diff --git a/ios/manifest b/ios/manifest
index 76a0391..86686d4 100644
--- a/ios/manifest
+++ b/ios/manifest
@@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
-version: 1.6.0
+version: 1.7.0
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: com.williamrijksen.onesignal
diff --git a/ios/module.xcconfig b/ios/module.xcconfig
index cdb1cf2..3ae95b9 100644
--- a/ios/module.xcconfig
+++ b/ios/module.xcconfig
@@ -25,6 +25,6 @@
//
// IMPORTANT NOTE: always use $(inherited) in your overrides
//
-FRAMEWORK_SEARCH_PATHS=$(SRCROOT)/../../modules/iphone/com.williamrijksen.onesignal/1.6.0/platform "~/Library/Application\ Support/Titanium/modules/iphone/com.williamrijksen.onesignal/1.6.0/platform"
+FRAMEWORK_SEARCH_PATHS=$(SRCROOT)/../../modules/iphone/com.williamrijksen.onesignal/1.7.0/platform "~/Library/Application\ Support/Titanium/modules/iphone/com.williamrijksen.onesignal/1.7.0/platform"
OTHER_LDFLAGS=$(inherited) -framework OneSignal -framework UserNotifications
LD_RUNPATH_SEARCH_PATHS= $(inherited) "@executable_path/Frameworks" $(FRAMEWORK_SEARCH_PATHS)
diff --git a/ios/platform/OneSignal.framework/Versions/A/Headers/OneSignal.h b/ios/platform/OneSignal.framework/Versions/A/Headers/OneSignal.h
index d3884ca..1a01a28 100755
--- a/ios/platform/OneSignal.framework/Versions/A/Headers/OneSignal.h
+++ b/ios/platform/OneSignal.framework/Versions/A/Headers/OneSignal.h
@@ -183,6 +183,7 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
@property (readonly, nonatomic) BOOL hasPrompted;
@property (readonly, nonatomic) OSNotificationPermission status;
+- (NSDictionary*)toDictionary;
@end
@@ -190,6 +191,7 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
@property (readonly) OSPermissionState* to;
@property (readonly) OSPermissionState* from;
+- (NSDictionary*)toDictionary;
@end
@@ -205,6 +207,7 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
@property (readonly, nonatomic) BOOL userSubscriptionSetting; // returns setSubscription state.
@property (readonly, nonatomic) NSString* userId; // AKA OneSignal PlayerId
@property (readonly, nonatomic) NSString* pushToken; // AKA Apple Device Token
+- (NSDictionary*)toDictionary;
@end
@@ -212,8 +215,8 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
@property (readonly) OSSubscriptionState* to;
@property (readonly) OSSubscriptionState* from;
-@property (readonly) BOOL becameSubscribed;
-@property (readonly) BOOL becameUnsubscribed;
+
+- (NSDictionary*)toDictionary;
@end
@@ -228,6 +231,7 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
@property (readonly) OSPermissionState* permissionStatus;
@property (readonly) OSSubscriptionState* subscriptionStatus;
+- (NSDictionary*)toDictionary;
@end
diff --git a/ios/platform/OneSignal.framework/Versions/A/OneSignal b/ios/platform/OneSignal.framework/Versions/A/OneSignal
index ff68d31..99c3c04 100755
Binary files a/ios/platform/OneSignal.framework/Versions/A/OneSignal and b/ios/platform/OneSignal.framework/Versions/A/OneSignal differ
diff --git a/ios/titanium.xcconfig b/ios/titanium.xcconfig
index 06e541c..9b28fbf 100644
--- a/ios/titanium.xcconfig
+++ b/ios/titanium.xcconfig
@@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
-TITANIUM_SDK_VERSION = 6.0.3.GA
+TITANIUM_SDK_VERSION = 6.1.2.GA
//