Skip to content

Commit

Permalink
Merge pull request #127 from urbanairship/MOBILE-2533
Browse files Browse the repository at this point in the history
[MOBILE-2533] Update Unity to latest SDKs
  • Loading branch information
Apekka authored Dec 2, 2021
2 parents 93bd8a0 + 1df0f31 commit 5f43c55
Show file tree
Hide file tree
Showing 17 changed files with 532 additions and 321 deletions.
2 changes: 1 addition & 1 deletion Assets/Plugins/iOS/UAUnityMessageViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "UAMessageCenterResources.h"
#import "UAMessageCenterLocalization.h"
#else
@import Airship;
@import AirshipKit;
#endif

NS_ASSUME_NONNULL_BEGIN
Expand Down
32 changes: 18 additions & 14 deletions Assets/Plugins/iOS/UAUnityPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "UADefaultMessageCenterUI.h"
#import "UAAssociatedIdentifiers.h"
#else
@import Airship;
@import AirshipKit;
#endif

extern void UnitySendMessage(const char *, const char *, const char *);
Expand Down Expand Up @@ -41,15 +41,6 @@ void UAUnityPlugin_removeTag(const char* tag);

const char* UAUnityPlugin_getChannelId();

#pragma mark -
#pragma mark UA Location Functions

bool UAUnityPlugin_isLocationEnabled();
void UAUnityPlugin_setLocationEnabled(bool enabled);

bool UAUnityPlugin_isBackgroundLocationAllowed();
void UAUnityPlugin_setBackgroundLocationAllowed(bool allowed);

#pragma mark -
#pragma mark Custom Events
void UAUnityPlugin_addCustomEvent(const char *customEvent);
Expand Down Expand Up @@ -97,10 +88,23 @@ void UAUnityPlugin_editNamedUserAttributes(const char *payload);

#pragma mark -
#pragma mark Data Collection
bool UAUnityPlugin_isDataCollectionEnabled();
void UAUnityPlugin_setDataCollectionEnabled(bool enabled);
bool UAUnityPlugin_isPushTokenRegistrationEnabled();
void UAUnityPlugin_setPushTokenRegistrationEnabled(bool enabled);
void UAUnityPlugin_setEnabledFeatures(const char *features);
void UAUnityPlugin_enableFeatures(const char *features);
void UAUnityPlugin_disableFeatures(const char *features);
bool UAUnityPlugin_isFeatureEnabled(const char *feature);
bool UAUnityPlugin_isAnyFeatureEnabled();
const char* UAUnityPlugin_getEnabledFeatures();

#pragma mark -
#pragma mark Preference Center

void UAUnityPlugin_openPreferenceCenter(NSString *preferenceCenterId);

#pragma mark -
#pragma mark Helpers
bool isValidFeature(NSArray *features);
UAFeatures stringToFeature(NSArray *features);
NSArray * featureToString(UAFeatures features);

@interface UAUnityPlugin : NSObject <UAPushNotificationDelegate, UADeepLinkDelegate, UAMessageCenterDisplayDelegate>

Expand Down
221 changes: 160 additions & 61 deletions Assets/Plugins/iOS/UAUnityPlugin.m

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Assets/Scripts/UrbanAirshipBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright Airship and Contributors */

using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -10,8 +10,6 @@ public class UrbanAirshipBehaviour : MonoBehaviour {
public string addTagOnStart;

void Awake () {
UAirship.Shared.DataCollectionEnabled = true;
UAirship.Shared.PushTokenRegistrationEnabled = true;
UAirship.Shared.UserNotificationsEnabled = true;
}

Expand All @@ -20,6 +18,9 @@ void Start () {
UAirship.Shared.AddTag (addTagOnStart);
}

string[] allenable = new string[] { "FEATURE_ALL" };
UAirship.Shared.SetEnabledFeatures(allenable);

UAirship.Shared.OnPushReceived += OnPushReceived;
UAirship.Shared.OnChannelUpdated += OnChannelUpdated;
UAirship.Shared.OnDeepLinkReceived += OnDeepLinkReceived;
Expand Down
20 changes: 16 additions & 4 deletions Assets/UrbanAirship/Editor/UAConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum CloudSite {
public String UrlAllowListScopeJavaScriptInterface { get; set; }

[SerializeField]
public bool DataCollectionOptInEnabled { get; set; }
public String EnabledFeatures { get; set; }

[SerializeField]
public String AndroidNotificationIcon { get; set; }
Expand Down Expand Up @@ -126,7 +126,7 @@ public UAConfig (UAConfig config) {
this.UrlAllowListScopeOpenURL = config.UrlAllowListScopeOpenURL;
this.UrlAllowListScopeJavaScriptInterface = config.UrlAllowListScopeJavaScriptInterface;

this.DataCollectionOptInEnabled = config.DataCollectionOptInEnabled;
this.EnabledFeatures = config.EnabledFeatures;

this.NotificationPresentationOptionAlert = config.NotificationPresentationOptionAlert;
this.NotificationPresentationOptionBadge = config.NotificationPresentationOptionBadge;
Expand Down Expand Up @@ -271,7 +271,6 @@ private void GenerateIOSAirshipConfig () {

rootDict.SetString ("site", Site.ToString());
rootDict.SetBoolean ("inProduction", InProduction);
rootDict.SetBoolean ("dataCollectionOptInEnabled", DataCollectionOptInEnabled);

if (!String.IsNullOrEmpty(UrlAllowList))
{
Expand Down Expand Up @@ -300,6 +299,15 @@ private void GenerateIOSAirshipConfig () {
}
}

if (!String.IsNullOrEmpty(EnabledFeatures))
{
PlistElementArray enabledFeaturesConfig = rootDict.CreateArray("enabledFeatures");
foreach (string feature in EnabledFeatures.Split(','))
{
enabledFeaturesConfig.AddString(feature);
}
}

PlistElementDict customConfig = rootDict.CreateDict ("customConfig");
customConfig.SetBoolean ("notificationPresentationOptionAlert", NotificationPresentationOptionAlert);
customConfig.SetBoolean ("notificationPresentationOptionBadge", NotificationPresentationOptionBadge);
Expand Down Expand Up @@ -355,7 +363,6 @@ private void GenerateAndroidAirshipConfig () {

xmlWriter.WriteAttributeString ("site", Site.ToString());
xmlWriter.WriteAttributeString ("inProduction", (InProduction ? "true" : "false"));
xmlWriter.WriteAttributeString ("dataCollectionOptInEnabled", (DataCollectionOptInEnabled ? "true" : "false"));

if (!String.IsNullOrEmpty(UrlAllowList))
{
Expand All @@ -372,6 +379,11 @@ private void GenerateAndroidAirshipConfig () {
xmlWriter.WriteAttributeString ("urlAllowListScopeJavaScriptInterface", UrlAllowListScopeJavaScriptInterface.ToString());
}

if (!String.IsNullOrEmpty(EnabledFeatures))
{
xmlWriter.WriteAttributeString ("enabledFeatures", EnabledFeatures.ToString());
}

if (!String.IsNullOrEmpty (AndroidNotificationIcon)) {
xmlWriter.WriteAttributeString ("notificationIcon", AndroidNotificationIcon);
}
Expand Down
10 changes: 4 additions & 6 deletions Assets/UrbanAirship/Editor/UAConfigEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ void OnGUI () {
CreateSection ("Common", () => {
config.InProduction = EditorGUILayout.Toggle ("inProduction", config.InProduction);
config.Site = (UAConfig.CloudSite) EditorGUILayout.EnumPopup ("Cloud Site", config.Site);
config.DataCollectionOptInEnabled = EditorGUILayout.Toggle ("Data Collection Opt-In", config.DataCollectionOptInEnabled);
GUILayout.Label ("When data collection opt-in is enabled, data collection will be disabled by default until the app enables it by calling " +
"`UAirship.Shared.DataCollectionEnabled = true`. When disabled, the device will stop collection and sending data for named user, events, tags " +
"attributes, associated identifiers, and location from the device. Push notifications will continue to work only if " +
"`UAirship.Shared.PushTokenRegistrationEnabled = true` is called, otherwise it will default to the current state of DataCollectionEnabled.",
EditorStyles.wordWrappedMiniLabel);
});

CreateSection ("URL Allow List", () => {
Expand All @@ -49,6 +43,10 @@ void OnGUI () {
config.UrlAllowListScopeJavaScriptInterface = EditorGUILayout.TextField ("Scope JS Interface", config.UrlAllowListScopeJavaScriptInterface);
});

CreateSection ("Data Collection", () => {
config.EnabledFeatures = EditorGUILayout.TextField ("Enabled Features", config.EnabledFeatures);
});

CreateSection ("Android Settings", () => {
config.GenerateGoogleJsonConfig = EditorGUILayout.Toggle ("Process google-service", config.GenerateGoogleJsonConfig);
config.AndroidNotificationAccentColor = EditorGUILayout.TextField ("Notification Accent Color", config.AndroidNotificationAccentColor);
Expand Down
15 changes: 9 additions & 6 deletions Assets/UrbanAirship/Editor/UADependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
</repositories>
</androidPackage>

<!-- Urban Airship Location -->
<androidPackage spec="com.urbanairship.android:urbanairship-location:__ANDROID_AIRSHIP_VERSION__">
<!-- Urban Airship FCM -->
<androidPackage spec="com.urbanairship.android:urbanairship-fcm:__ANDROID_AIRSHIP_VERSION__">
<repositories>
<repository>https://urbanairship.bintray.com/android</repository>
</repositories>
</androidPackage>

<!-- Urban Airship FCM -->
<androidPackage spec="com.urbanairship.android:urbanairship-fcm:__ANDROID_AIRSHIP_VERSION__">
<!-- Urban Airship Preference Center -->
<androidPackage spec="com.urbanairship.android:urbanairship-preference-center:__ANDROID_AIRSHIP_VERSION__">
<repositories>
<repository>https://urbanairship.bintray.com/android</repository>
</repositories>
Expand All @@ -39,8 +39,11 @@
<iosPods>

<!-- iosPod -->
<iosPod name="Airship" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />
<iosPod name="Airship/Location" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />
<iosPod name="Airship/Core" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />
<iosPod name="Airship/MessageCenter" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />
<iosPod name="Airship/Automation" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />
<iosPod name="Airship/ExtendedActions" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />
<iosPod name="Airship/PreferenceCenter" version="__IOS_AIRSHIP_VERSION__" minTargetSdk="11.0" />

</iosPods>

Expand Down
77 changes: 41 additions & 36 deletions Assets/UrbanAirship/Platforms/Android/UAirshipPluginAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UrbanAirship {
Expand Down Expand Up @@ -44,24 +45,6 @@ public string ChannelId {
}
}

public bool LocationEnabled {
get {
return Call<bool> ("isLocationEnabled");
}
set {
Call ("setLocationEnabled", value);
}
}

public bool BackgroundLocationAllowed {
get {
return Call<bool> ("isBackgroundLocationAllowed");
}
set {
Call ("setBackgroundLocationAllowed", value);
}
}

public string NamedUserId {
get {
return Call<string> ("getNamedUserId");
Expand Down Expand Up @@ -180,6 +163,46 @@ public void EditNamedUserAttributes (string payload) {
Call ("editNamedUserAttributes", payload);
}

public void OpenPreferenceCenter (string preferenceCenterId) {
Call ("openPreferenceCenter", preferenceCenterId);
}

public void SetEnabledFeatures (string[] enabledFeatures) {
Call ("setEnabledFeatures", MakeJavaArray(enabledFeatures));
}

public void EnableFeatures (string[] enabledFeatures) {
Call ("enableFeatures", MakeJavaArray(enabledFeatures));
}

public void DisableFeatures (string[] disabledFeatures) {
Call ("disableFeatures", MakeJavaArray(disabledFeatures));
}

public bool IsFeatureEnabled (string[] features) {
return Call<bool> ("isFeatureEnabled", MakeJavaArray(features));
}

public bool IsAnyFeatureEnabled (string[] features) {
return Call<bool> ("isAnyFeatureEnabled", MakeJavaArray(features));
}

public string[] GetEnabledFeatures () {
return Call<string[]> ("getEnabledFeatures");
}

/// Internal method to make a Java Array with an array of String values, to be used with the
/// "setEnabledFeatures" method.
private AndroidJavaObject MakeJavaArray(string [] values) {
AndroidJavaClass arrayClass = new AndroidJavaClass("java.lang.reflect.Array");
AndroidJavaObject arrayObject = arrayClass.CallStatic<AndroidJavaObject>("newInstance", new AndroidJavaClass("java.lang.String"), values.Count());
for (int i=0; i<values.Count(); ++i) {
arrayClass.CallStatic("set", arrayObject, i, new AndroidJavaObject("java.lang.String", values[i]));
}

return arrayObject;
}

private void Call (string method, params object[] args) {
if (androidPlugin != null) {
androidPlugin.Call (method, args);
Expand All @@ -192,24 +215,6 @@ private T Call<T> (string method, params object[] args) {
}
return default (T);
}

public bool DataCollectionEnabled {
get {
return Call<bool> ("isDataCollectionEnabled");
}
set {
Call ("setDataCollectionEnabled", value);
}
}

public bool PushTokenRegistrationEnabled {
get {
return Call<bool> ("isPushTokenRegistrationEnabled");
}
set {
Call ("setPushTokenRegistrationEnabled", value);
}
}
}
}

Expand Down
34 changes: 14 additions & 20 deletions Assets/UrbanAirship/Platforms/IUAirshipPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ string ChannelId {
get;
}

bool LocationEnabled {
get;
set;
}

bool BackgroundLocationAllowed {
get;
set;
}

string NamedUserId {
get;
set;
Expand All @@ -40,16 +30,6 @@ GameObject Listener {
set;
}

bool DataCollectionEnabled {
get;
set;
}

bool PushTokenRegistrationEnabled {
get;
set;
}

string GetDeepLink (bool clear);

string GetIncomingPush (bool clear);
Expand Down Expand Up @@ -94,6 +74,20 @@ int MessageCenterCount {

void EditNamedUserAttributes (string payload);

void OpenPreferenceCenter (string preferenceCenterId);

void SetEnabledFeatures (string[] enabledFeatures);

void EnableFeatures (string[] enabledFeatures);

void DisableFeatures (string[] disabledFeatures);

bool IsFeatureEnabled (string[] features);

bool IsAnyFeatureEnabled (string[] features);

string[] GetEnabledFeatures ();

TimeSpan InAppAutomationDisplayInterval {
get;
set;
Expand Down
11 changes: 7 additions & 4 deletions Assets/UrbanAirship/Platforms/StubbedPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class StubbedPlugin : IUAirshipPlugin {
public bool UserNotificationsEnabled { get; set; }
public string Tags { get { return null; } }
public string ChannelId { get { return null; } }
public bool LocationEnabled { get; set; }
public bool BackgroundLocationAllowed { get; set; }
public string NamedUserId { get; set; }
public TimeSpan InAppAutomationDisplayInterval { get; set; }
public bool InAppAutomationPaused { get; set; }
Expand All @@ -34,7 +32,12 @@ public void EditNamedUserTagGroups (string payload) { }
public void EditChannelTagGroups (string payload) { }
public void EditChannelAttributes (string payload) { }
public void EditNamedUserAttributes (string payload) { }
public bool DataCollectionEnabled { get; set; }
public bool PushTokenRegistrationEnabled { get; set; }
public void OpenPreferenceCenter (string preferenceCenterId) { }
public void SetEnabledFeatures (string[] enabledFeatures) { }
public void EnableFeatures (string[] enabledFeatures) { }
public void DisableFeatures (string[] disabledFeatures) { }
public bool IsFeatureEnabled (string[] features) { return false; }
public bool IsAnyFeatureEnabled (string[] features) { return false; }
public string[] GetEnabledFeatures () { return null; }
}
}
Loading

0 comments on commit 5f43c55

Please sign in to comment.