Skip to content

Commit

Permalink
In App Messaging (#550)
Browse files Browse the repository at this point in the history
- Includes support for native iOS SDK 2.11.0
- In-App Messaging
  • Loading branch information
Rodrigo Gomez Palacio authored Sep 11, 2019
1 parent 97b7e3c commit 9a9f4b2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.5.2",
"version": "2.6.0",
"name": "onesignal-cordova-plugin",
"cordova_name": "OneSignal Push Notifications",
"description": "OneSignal is a high volume Push Notification service for mobile apps. In addition to basic notification delivery, OneSignal also provides tools to localize, target, schedule, and automate notifications that you send.",
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="onesignal-cordova-plugin"
version="2.5.2">
version="2.6.0">


<name>OneSignal Push Notifications</name>
Expand All @@ -27,7 +27,7 @@
</engines>

<platform name="android">
<framework src="com.onesignal:OneSignal:3.11.2" />
<framework src="com.onesignal:OneSignal:3.11.3" />
<framework src="build-extras-onesignal.gradle" custom="true" type="gradleReference" />

<config-file target="res/xml/config.xml" parent="/*">
Expand Down Expand Up @@ -83,7 +83,7 @@
<string>production</string>
</config-file>

<framework src="OneSignal" type="podspec" spec="2.10.1" />
<framework src="OneSignal" type="podspec" spec="2.11.0" />
<header-file src="src/ios/OneSignalPush.h" />
<source-file src="src/ios/OneSignalPush.m" />

Expand Down
50 changes: 34 additions & 16 deletions src/ios/OneSignalPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#import "OneSignalPush.h"
#import <OneSignal/OneSignal.h>

NSString* notficationReceivedCallbackId;
NSString* notficationOpenedCallbackId;
NSString* notificationReceivedCallbackId;
NSString* notificationOpenedCallbackId;
NSString* getTagsCallbackId;
NSString* getIdsCallbackId;
NSString* postNotificationCallbackId;
Expand Down Expand Up @@ -71,7 +71,7 @@ void processNotificationReceived(OSNotification* _notif) {
options:NSJSONReadingMutableContainers
error:&jsonError];
if(!jsonError) {
successCallback(notficationReceivedCallbackId, json);
successCallback(notificationReceivedCallbackId, json);
notification = nil;
}
}
Expand All @@ -84,16 +84,15 @@ void processNotificationOpened(OSNotificationOpenedResult* result) {
options:NSJSONReadingMutableContainers
error:&jsonError];
if(!jsonError) {
successCallback(notficationOpenedCallbackId, json);
successCallback(notificationOpenedCallbackId, json);
actionNotification = nil;
}
}

void initOneSignalObject(NSDictionary* launchOptions, const char* appId, int displayOption, BOOL inAppLaunchURL, BOOL autoPrompt, BOOL fromColdStart) {
[OneSignal setValue:@"cordova" forKey:@"mSDKType"];

NSString* appIdStr = (appId ? [NSString stringWithUTF8String: appId] : nil);

NSString* appIdStr = (appId ? [NSString stringWithUTF8String: appId] : nil);
NSDictionary *iOSSettings = initialLaunchFired ? @{kOSSettingsKeyAutoPrompt : @(autoPrompt),
kOSSettingsKeyInFocusDisplayOption : @(displayOption),
kOSSettingsKeyInAppLaunchURL : @(inAppLaunchURL),
Expand All @@ -111,7 +110,7 @@ void initOneSignalObject(NSDictionary* launchOptions, const char* appId, int dis
if (pluginCommandDelegate)
processNotificationOpened(openResult);
} settings: iOSSettings];

initialLaunchFired = true;
}

Expand Down Expand Up @@ -174,10 +173,11 @@ -(void)onOSEmailSubscriptionChanged:(OSEmailSubscriptionStateChanges *)stateChan
}

- (void)setNotificationReceivedHandler:(CDVInvokedUrlCommand*)command {
notficationReceivedCallbackId = command.callbackId;
notificationReceivedCallbackId = command.callbackId;
}

- (void)setNotificationOpenedHandler:(CDVInvokedUrlCommand*)command {
notficationOpenedCallbackId = command.callbackId;
notificationOpenedCallbackId = command.callbackId;
}

- (void)init:(CDVInvokedUrlCommand*)command {
Expand Down Expand Up @@ -370,24 +370,42 @@ - (void)removeExternalUserId:(CDVInvokedUrlCommand *)command {
[OneSignal removeExternalUserId];
}

/**
* In-App Messaging
*/

- (void)setInAppMessageClickHandler:(CDVInvokedUrlCommand*)command {
// unimplemented in ios
[OneSignal setInAppMessageClickHandler:^(OSInAppMessageAction* action) {
NSDictionary *result = @{
@"clickName": action.clickName ?: [NSNull null],
@"clickUrl" : action.clickUrl.absoluteString ?: [NSNull null],
@"firstClick" : @(action.firstClick),
@"closesMessage" : @(action.closesMessage)
};
successCallback(command.callbackId, result);
}
];
}

- (void)addTriggers:(CDVInvokedUrlCommand*)command {
// unimplemented in ios
[OneSignal addTriggers:command.arguments[0]];
}

- (void)removeTriggersForKeys:(CDVInvokedUrlCommand*)command {
// unimplemented in ios
[OneSignal removeTriggersForKeys:command.arguments[0]];
}

- (void)getTriggerValueForKey:(CDVInvokedUrlCommand*)command {
// unimplemented in ios
NSString *key = command.arguments[0];
NSString *val = [OneSignal getTriggerValueForKey:key];
NSDictionary *result = @{
@"value" : val ?: [NSNull null]
};
successCallback(command.callbackId, result);
}

- (void)pauseInAppMessages:(CDVInvokedUrlCommand*)command {
// unimplemented in ios
bool pause = [command.arguments[0] boolValue];
[OneSignal pauseInAppMessages:pause];
}
@end

@end
6 changes: 6 additions & 0 deletions www/OneSignal.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ OneSignal.prototype.userProvidedPrivacyConsent = function(callback) {
*/

OneSignal.prototype.addTriggers = function(triggers) {
Object.keys(triggers).forEach((key)=>{
// forces values to be string types
if (typeof triggers[key] !== "string") {
triggers[key] = JSON.stringify(triggers[key]);
}
});
cordova.exec(function() {}, function() {}, "OneSignalPush", "addTriggers", [triggers]);
}

Expand Down

0 comments on commit 9a9f4b2

Please sign in to comment.