Skip to content

Commit

Permalink
Merge pull request #114 from OneSignal/misc_native_fixes
Browse files Browse the repository at this point in the history
Updated native SDK code, Android data types, and iOS isAppInFocus
  • Loading branch information
jkasten2 authored Nov 8, 2016
2 parents 1579038 + 6977b47 commit e3992c4
Show file tree
Hide file tree
Showing 15 changed files with 596 additions and 370 deletions.
17 changes: 1 addition & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Modified MIT License

Copyright 2015 OneSignal
Copyright 2016 OneSignal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,21 +39,6 @@ Includes portions from the Google GcmClient demo project:
See the License for the specific language governing permissions and
limitations under the License.

Includes Portions Copyright 2014 StackMob:
Copyright 2014 StackMob

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Includes portions from RootTools:
Copyright (c) 2012 Stephen Erickson, Chris Ravenscroft, Dominik Schuermann, Adam Shanks

Expand Down
5 changes: 2 additions & 3 deletions build-extras-onesignal.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def manifest = new XmlSlurper().parse(file("AndroidManifest.xml"))
android.defaultConfig {
applicationId manifest.@package.text()
manifestPlaceholders = [manifestApplicationId: "${android.defaultConfig.applicationId}",
onesignal_app_id: "", // Use from code for now.
onesignal_google_project_number: ""]
manifestPlaceholders = [onesignal_app_id: "", // Use from code for now.
onesignal_google_project_number: "REMOTE"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.6",
"version": "2.0.7",
"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
9 changes: 7 additions & 2 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.0.6">
version="2.0.7">


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

<platform name="android">
<framework src="com.onesignal:OneSignal:3.3.0@aar" />
<framework src="com.onesignal:OneSignal:3.4.1@aar" />

<framework src="com.google.android.gms:play-services-gcm:+" />
<!-- play-services-analytics is only required when gms version 8.1.0 or older is used. -->
Expand Down Expand Up @@ -95,6 +95,9 @@
<header-file src="src/ios/OneSignalTracker.h" />
<header-file src="src/ios/OneSignalWebView.h" />
<source-file src="src/ios/OneSignalPush.h" />
<source-file src="src/ios/OneSignalSelectorHelpers.h" />
<source-file src="src/ios/UNUserNotificationCenter+OneSignal.h" />


<!-- Implementation -->
<source-file src="src/ios/OneSignal.m" />
Expand All @@ -111,6 +114,8 @@
<source-file src="src/ios/OneSignalHelper.m" />
<source-file src="src/ios/OneSignalWebView.m" />
<source-file src="src/ios/OneSignalPush.m" />
<source-file src="src/ios/OneSignalSelectorHelpers.m" />
<source-file src="src/ios/UNUserNotificationCenter+OneSignal.m" />

<header-file src="src/ios/OneSignal-Prefix.pch" />

Expand Down
76 changes: 37 additions & 39 deletions src/android/com/plugin/gcm/OneSignalPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,17 @@ public class OneSignalPush extends CordovaPlugin {

// This is to prevent an issue where if two Javascript calls are made to OneSignal expecting a callback then only one would fire.
private static void callbackSuccess(CallbackContext callbackContext, JSONObject jsonObject) {
if(jsonObject == null){ // in case there are no data
if (jsonObject == null) // in case there are no data
jsonObject = new JSONObject();
}

if(jsonObject.has("payload")) {
try {
JSONObject payload = jsonObject.getJSONObject("payload");
if (payload.has("additionalData")) {
payload.put("additionalData", new JSONObject(payload.getString("additionalData")));
jsonObject.put("payload", payload);
}
} catch (Throwable t) {t.printStackTrace();}
}

PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, jsonObject);
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
}

private static void callbackError(CallbackContext callbackContext, JSONObject jsonObject) {
if(jsonObject == null) { // in case there are no data
if (jsonObject == null) // in case there are no data
jsonObject = new JSONObject();
}

PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, jsonObject);
pluginResult.setKeepCallback(true);
Expand Down Expand Up @@ -169,12 +157,13 @@ public void idsAvailable(String userId, String registrationId) {
try {
jsonIds.put("userId", userId);
if (registrationId != null)
jsonIds.put("pushToken", registrationId);
jsonIds.put("pushToken", registrationId);
else
jsonIds.put("pushToken", "");
jsonIds.put("pushToken", "");

callbackSuccess(jsIdsAvailableCallBack, jsonIds);
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
Expand All @@ -184,7 +173,8 @@ public void idsAvailable(String userId, String registrationId) {
else if (SEND_TAGS.equals(action)) {
try {
OneSignal.sendTags(data.getJSONObject(0));
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
result = true;
Expand All @@ -193,10 +183,10 @@ else if (DELETE_TAGS.equals(action)) {
try {
Collection<String> list = new ArrayList<String>();
for (int i = 0; i < data.length(); i++)
list.add(data.get(i).toString());
list.add(data.get(i).toString());
OneSignal.deleteTags(list);
result = true;
} catch (Throwable t) {
} catch (Throwable t) {
t.printStackTrace();
}
}
Expand All @@ -208,23 +198,26 @@ else if (ENABLE_VIBRATE.equals(action)) {
try {
OneSignal.enableVibrate(data.getBoolean(0));
result = true;
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
else if (ENABLE_SOUND.equals(action)) {
try {
OneSignal.enableSound(data.getBoolean(0));
result = true;
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
else if (SET_SUBSCRIPTION.equals(action)) {
try {
OneSignal.setSubscription(data.getBoolean(0));
result = true;
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
Expand All @@ -233,20 +226,21 @@ else if (POST_NOTIFICATION.equals(action)) {
JSONObject jo = data.getJSONObject(0);
final CallbackContext jsPostNotificationCallBack = callbackContext;
OneSignal.postNotification(jo,
new PostNotificationResponseHandler() {
@Override
public void onSuccess(JSONObject response) {
callbackSuccess(jsPostNotificationCallBack, response);
}

@Override
public void onFailure(JSONObject response) {
callbackError(jsPostNotificationCallBack, response);
}
});
new PostNotificationResponseHandler() {
@Override
public void onSuccess(JSONObject response) {
callbackSuccess(jsPostNotificationCallBack, response);
}
@Override
public void onFailure(JSONObject response) {
callbackError(jsPostNotificationCallBack, response);
}
});

result = true;
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
Expand All @@ -263,14 +257,16 @@ else if (SET_LOG_LEVEL.equals(action)) {
try {
JSONObject jo = data.getJSONObject(0);
OneSignal.setLogLevel(jo.getInt("logLevel"), jo.getInt("visualLevel"));
} catch(Throwable t) {
}
catch(Throwable t) {
t.printStackTrace();
}
}
else if (CLEAR_ONESIGNAL_NOTIFICATIONS.equals(action)) {
try {
OneSignal.clearOneSignalNotifications();
} catch(Throwable t) {
}
catch(Throwable t) {
t.printStackTrace();
}
}
Expand All @@ -295,7 +291,8 @@ public CordovaNotificationReceivedHandler(CallbackContext inCallbackContext) {
public void notificationReceived(OSNotification notification) {
try {
callbackSuccess(jsNotificationReceivedCallBack, new JSONObject(notification.stringify()));
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
Expand All @@ -313,7 +310,8 @@ public CordovaNotificationOpenedHandler(CallbackContext inCallbackContext) {
public void notificationOpened(OSNotificationOpenResult result) {
try {
callbackSuccess(jsNotificationOpenedCallBack, new JSONObject(result.stringify()));
} catch (Throwable t) {
}
catch (Throwable t) {
t.printStackTrace();
}
}
Expand Down
39 changes: 21 additions & 18 deletions src/ios/OneSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
REST API: https://documentation.onesignal.com/docs/server-api-overview
Create Notification API: https://documentation.onesignal.com/docs/notifications-create-notification
***/
***/

#import <Foundation/Foundation.h>

Expand All @@ -54,8 +54,8 @@

@protocol OSUserNotificationCenterDelegate <NSObject>
@optional
- (void)userNotificationCenter:(id)center willPresentNotification:(id)notification withCompletionHandler:(void (^)(NSUInteger options))completionHandler;
- (void)userNotificationCenter:(id)center didReceiveNotificationResponse:(id)response withCompletionHandler:(void (^)())completionHandler;
- (void)userNotificationCenter:(id)center willPresentNotification:(id)notification withCompletionHandler:(void (^)(NSUInteger options))completionHandler __deprecated_msg("Can use your own delegate as normal.");
- (void)userNotificationCenter:(id)center didReceiveNotificationResponse:(id)response withCompletionHandler:(void (^)())completionHandler __deprecated_msg("Can use your own delegate as normal.");
@end

#endif
Expand Down Expand Up @@ -148,14 +148,17 @@ typedef OSNotificationDisplayType OSInFocusDisplayOption;
Set to false when app is in focus and in-app alerts are disabled, or the remote notification is silent. */
@property(readonly, getter=wasShown)BOOL shown;

/* Set to true if the app was in focus when the notification */
@property(readonly, getter=wasAppInFocus)BOOL isAppInFocus;

/* Set to true when the received notification is silent
Silent means there is no alert, sound, or badge payload in the aps dictionary
requires remote-notification within UIBackgroundModes array of the Info.plist */
@property(readonly, getter=isSilentNotification)BOOL silentNotification;

/* iOS 10+: Indicates wether or not the received notification has mutableContent : 1 assigned to its payload
Used for UNNotificationServiceExtension to launch extension.
*/
*/
#if XC8_AVAILABLE
@property(readonly, getter=hasMutableContent)BOOL mutableContent;
#endif
Expand Down Expand Up @@ -190,27 +193,27 @@ typedef void (^OSHandleNotificationReceivedBlock)(OSNotification* notification);
typedef void (^OSHandleNotificationActionBlock)(OSNotificationOpenedResult * result);

/*Dictionary of keys to pass alongside the init serttings*/

/*Let OneSignal directly promt for push notifications on init*/
extern NSString * const kOSSettingsKeyAutoPrompt;

/*Enable the default in-app alerts*/
extern NSString * const kOSSettingsKeyInAppAlerts;

/*Enable In-App display of Launch URLs*/
extern NSString * const kOSSettingsKeyInAppLaunchURL;

/* iOS10+ -
/* iOS10+ -
Set notificaion's in-focus display option.
Value must be an OSNotificationDisplayType enum
*/
*/
extern NSString * const kOSSettingsKeyInFocusDisplayOption;

/**
OneSignal provides a high level interface to interact with OneSignal's push service.
OneSignal is a singleton for applications which use a globally available client to share configuration settings.
You should avoid creating instances of this class at all costs. Instead, access its instance methods.
Include `#import <OneSignal/OneSignal.h>` in your application files to access OneSignal's methods.
OneSignal provides a high level interface to interact with OneSignal's push service.
OneSignal is a singleton for applications which use a globally available client to share configuration settings.
You should avoid creating instances of this class at all costs. Instead, access its instance methods.
Include `#import <OneSignal/OneSignal.h>` in your application files to access OneSignal's methods.
**/
@interface OneSignal : NSObject

Expand All @@ -227,16 +230,16 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
/**
Initialize OneSignal. Sends push token to OneSignal so you can later send notifications.
*/
*/

// - Initialization
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId;
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback;
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings;
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationReceived:(OSHandleNotificationReceivedBlock)receivedCallback handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings;
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationReceived:(OSHandleNotificationReceivedBlock)erceivedCallback handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings;

+ (NSString*)app_id;

// Only use if you passed FALSE to autoRegister
+ (void)registerForPushNotifications;

Expand Down Expand Up @@ -276,10 +279,10 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
// Optional method that sends us the user's email as an anonymized hash so that we can better target and personalize notifications sent to that user across their devices.
+ (void)syncHashedEmail:(NSString*)email;

// - iOS 10 BETA features currently only available on XCode 8 & iOS 10.0+
// - iOS 10 features currently only available on XCode 8 & iOS 10.0+
#if XC8_AVAILABLE
+ (void)setNotificationCenterDelegate:(id<OSUserNotificationCenterDelegate>)delegate;
+ (id<OSUserNotificationCenterDelegate>)notificationCenterDelegate;
+ (void)setNotificationCenterDelegate:(id<OSUserNotificationCenterDelegate>)delegate __deprecated_msg("Can use your own delegate as normal.");
+ (id<OSUserNotificationCenterDelegate>)notificationCenterDelegate __deprecated_msg("Can use your own delegate as normal.");
#endif

@end
Loading

0 comments on commit e3992c4

Please sign in to comment.