Skip to content

Commit

Permalink
WP8.1 support + other fixes
Browse files Browse the repository at this point in the history
* Added support for Windows Phone 8.1 projects.
* Fixed Android issue where postNotification was not formatting UTF-8 notifications correctly.
* Fixed iOS bug where notifications would clear when opening / resuming the app.
  - Notifications will still be cleared in this way when a badge is set.
    - This is due to an iOS limitation where clearing the badge count has a side effect of clearing all notifications from the app.
  - iOS 6 & 7 - When a notification is opened all other notifications from the app will still be cleared.
    - This logic remains otherwise notifications can be tapped on multiple times.
* Fixed bug where if content-available was set the notification would be marked opened when received and again when it was opened.
  • Loading branch information
jkasten2 committed Aug 11, 2015
1 parent 6804c08 commit f4547ee
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 24 deletions.
Binary file not shown.
10 changes: 6 additions & 4 deletions UnityOneSignalExample/Assets/Plugins/OneSignal/OneSignal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
* THE SOFTWARE.
*/

#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8)
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8 || UNITY_WP_8_1)
#define ONESIGNAL_PLATFORM
#endif

#if !UNITY_EDITOR && UNITY_ANDROID
#define ANDROID_ONLY
#endif

#if ONESIGNAL_PLATFORM && !UNITY_WP8
#if ONESIGNAL_PLATFORM && !UNITY_WP8 && !UNITY_WP_8_1
#define SUPPORTS_LOGGING
#endif

Expand Down Expand Up @@ -95,11 +95,13 @@ public static void Init(string appId, string googleProjectNumber, NotificationRe
#elif UNITY_IPHONE
oneSignalPlatform = new OneSignalIOS(gameObjectName, appId, autoRegister, logLevel, visualLogLevel);
#elif UNITY_WP8
oneSignalPlatform = new OneSignalWP(appId);
oneSignalPlatform = new OneSignalWP80(appId);
#elif UNITY_WP_8_1
oneSignalPlatform = new OneSignalWPWNS(appId);
#endif
notificationDelegate = inNotificationDelegate;

#if !UNITY_WP8
#if !UNITY_WP8 && !UNITY_WP_8_1
GameObject go = new GameObject(gameObjectName);
go.AddComponent<OneSignal>();
DontDestroyOnLoad(go);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
using System.Collections;
using System.Collections.Generic;

class OneSignalWP : OneSignalPlatform {
class OneSignalWP80 : OneSignalPlatform {

public OneSignalWP(string appId) {
OneSignalSDK.OneSignal.Init(appId, (message, inAdditionalData, isActive) => {
OneSignalSDK_WP80.OneSignal.Init(appId, (message, inAdditionalData, isActive) => {
if (OneSignal.notificationDelegate != null) {
Dictionary<string, object> additionalData = null;
if (inAdditionalData != null)
Expand All @@ -45,33 +45,33 @@ public OneSignalWP(string appId) {
}

public void SendTag(string tagName, string tagValue) {
OneSignalSDK.OneSignal.SendTag(tagName, tagValue);
OneSignalSDK_WP80.OneSignal.SendTag(tagName, tagValue);
}

public void SendTags(IDictionary<string, string> tags) {
OneSignalSDK.OneSignal.SendTags(tags.ToDictionary(pair => pair.Key, pair=>(object)pair.Value));
OneSignalSDK_WP80.OneSignal.SendTags(tags.ToDictionary(pair => pair.Key, pair=>(object)pair.Value));
}

public void SendPurchase(double amount) {
OneSignalSDK.OneSignal.SendPurchase(amount);
OneSignalSDK_WP80.OneSignal.SendPurchase(amount);
}

public void GetTags() {
OneSignalSDK.OneSignal.GetTags((tags) => {
OneSignalSDK_WP80.OneSignal.GetTags((tags) => {
OneSignal.tagsReceivedDelegate(tags.ToDictionary(pair => pair.Key, pair=>(object)pair.Value));
});
}

public void DeleteTag(string key) {
OneSignalSDK.OneSignal.DeleteTag(key);
OneSignalSDK_WP80.OneSignal.DeleteTag(key);
}

public void DeleteTags(IList<string> key) {
OneSignalSDK.OneSignal.DeleteTags(key);
OneSignalSDK_WP80.OneSignal.DeleteTags(key);
}

public void IdsAvailable() {
OneSignalSDK.OneSignal.GetIdsAvailable((playerId, channelUri) => {
OneSignalSDK_WP80.OneSignal.GetIdsAvailable((playerId, channelUri) => {
OneSignal.idsAvailableDelegate(playerId, channelUri);
});
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions UnityOneSignalExample/Assets/Plugins/OneSignal/OneSignalWPWNS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Modified MIT License
*
* Copyright 2015 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 1. The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 2. All copies of substantial portions of the Software may only be used in connection
* with services provided by OneSignal.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using UnityEngine;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

#if UNITY_WP_8_1 && !UNITY_EDITOR

public class OneSignalWPWNS : OneSignalPlatform {

public OneSignalWPWNS(string appId) {
OneSignalSDK_WP_WNS.ExternalInitUnity.Init(appId, (message, inAdditionalData, isActive) => {
if (OneSignal.notificationDelegate != null) {
Dictionary<string, object> additionalData = null;
if (inAdditionalData != null)
additionalData = inAdditionalData.ToDictionary(pair => pair.Key, pair=>(object)pair.Value);
OneSignal.notificationDelegate(message, additionalData, isActive);
}
});
}

public void SendTag(string tagName, string tagValue) {
OneSignalSDK_WP_WNS.OneSignal.SendTag(tagName, tagValue);
}

public void SendTags(IDictionary<string, string> tags) {
OneSignalSDK_WP_WNS.OneSignal.SendTags(tags.ToDictionary(pair => pair.Key, pair=>(object)pair.Value));
}

public void SendPurchase(double amount) {
OneSignalSDK_WP_WNS.OneSignal.SendPurchase(amount);
}

public void GetTags() {
OneSignalSDK_WP_WNS.OneSignal.GetTags((tags) => {
OneSignal.tagsReceivedDelegate(tags.ToDictionary(pair => pair.Key, pair=>(object)pair.Value));
});
}

public void DeleteTag(string key) {
OneSignalSDK_WP_WNS.OneSignal.DeleteTag(key);
}

public void DeleteTags(IList<string> key) {
OneSignalSDK_WP_WNS.OneSignal.DeleteTags(key);
}

public void IdsAvailable() {
OneSignalSDK_WP_WNS.OneSignal.GetIdsAvailable((playerId, channelUri) => {
OneSignal.idsAvailableDelegate(playerId, channelUri);
});
}

// Not available the WP SDK.
public void EnableInAppAlertNotification(bool enable) { }

// Not available in WP SDK.
public void SetSubscription(bool enable) {}

// Not available in WP SDK.
public void PostNotification(Dictionary<string, object> data) { }

// Doesn't apply to Windows Phone: The Callback is setup in the constructor so this is never called.
public void FireNotificationReceivedEvent(string jsonString, OneSignal.NotificationReceived notificationReceived) {}

public void OnApplicationPause(bool paused) { } // Doesn't apply to Windows Phone: The Native SDK auto handles this.
public void RegisterForPushNotifications() { } // Doesn't apply to Windows Phone: The Native SDK always registers.

public void SetLogLevel(OneSignal.LOG_LEVEL logLevel, OneSignal.LOG_LEVEL visualLevel) {} // The Native SDK does not implement this.
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion UnityOneSignalExample/Assets/Plugins/OneSignal/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.2
1.11.0
Binary file not shown.
72 changes: 72 additions & 0 deletions UnityOneSignalExample/Assets/Plugins/OneSignalSDK_WP_WNS.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityOneSignalExample/Assets/Plugins/WSA.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
72 changes: 72 additions & 0 deletions UnityOneSignalExample/Assets/Plugins/WSA/Newtonsoft.Json.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Loading

0 comments on commit f4547ee

Please sign in to comment.