diff --git a/Assets/Plugins/Android/appboy-ui.aar b/Assets/Plugins/Android/appboy-ui.aar index c0687948c..efdff8fbc 100644 Binary files a/Assets/Plugins/Android/appboy-ui.aar and b/Assets/Plugins/Android/appboy-ui.aar differ diff --git a/Assets/Plugins/Android/appboy-unity.aar b/Assets/Plugins/Android/appboy-unity.aar index 19290cca8..771c552d7 100644 Binary files a/Assets/Plugins/Android/appboy-unity.aar and b/Assets/Plugins/Android/appboy-unity.aar differ diff --git a/Assets/Plugins/Android/appboy.aar b/Assets/Plugins/Android/appboy.aar index 79a50dba1..f84745f71 100644 Binary files a/Assets/Plugins/Android/appboy.aar and b/Assets/Plugins/Android/appboy.aar differ diff --git a/Assets/Plugins/Appboy/AppboyBinding.cs b/Assets/Plugins/Appboy/AppboyBinding.cs index 6a8cfdd64..aff13cd60 100755 --- a/Assets/Plugins/Appboy/AppboyBinding.cs +++ b/Assets/Plugins/Appboy/AppboyBinding.cs @@ -1,5 +1,8 @@ -// When developing, you can place #define UNITY_ANDROID or #define UNITY_IOS above this line -// in order to get correct syntax highlighting in the region you are working on. +// https://docs.unity3d.com/Manual/PlatformDependentCompilation.html +#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS) + #define HAS_BRAZE_SDK +#endif + using Appboy.Internal; using Appboy.Models; using Appboy.Utilities; @@ -10,14 +13,10 @@ using UnityEngine; /// -/// These methods can be called by Unity applications using iOS or Android in order to report +/// These methods can be called by Unity applications on supported platforms in order to report /// events, set user attributes, and control messaging /// namespace Appboy { - - public delegate void PushPromptResponseReceived(bool granted); - public delegate void PushTokenReceivedFromSystem(string token); - /// /// Types of messages that Braze can be configured to send to a GameObject method at runtime. /// @@ -77,584 +76,24 @@ public enum BrazeUnityMessageType { CONTENT_CARDS_UPDATED = 7 } - public class AppboyBinding : MonoBehaviour { - // Overloads - // These will call the associated binding method for the current live platform - public static void LogPurchase(string productId, string currencyCode, decimal price) { - LogPurchase(productId, currencyCode, price, 1); - } - - public static void IncrementCustomUserAttribute(string key) { - IncrementCustomUserAttribute(key, 1); - } - // End Overloads - -#if UNITY_IOS - void Start() { - Debug.Log("Starting Braze binding for iOS clients."); - } - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logCustomEvent(string eventName, string properties); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _changeUser(string userId); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logPurchase(string productId, string currencyCode, string price, int quantity, string properties); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserFirstName(string firstName); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserLastName(string lastName); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserPhoneNumber(string phoneNumber); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserAvatarImageURL(string imageURL); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserGender(int gender); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserEmail(string email); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserDateOfBirth(int year, int month, int day); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserCountry(string country); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserHomeCity(string city); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserEmailNotificationSubscriptionType(int emailNotificationSubscriptionType); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserPushNotificationSubscriptionType(int pushNotificationSubscriptionType); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeBool(string key, bool val); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeInt(string key, int val); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeFloat(string key, float val); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeString(string key, string val); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeToNow(string key); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeToSecondsFromEpoch(string key, long seconds); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _unsetCustomUserAttribute(string key); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _incrementCustomUserAttribute(string key, int incrementValue); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setCustomUserAttributeArray(string key, string[] array, int size); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _addToCustomUserAttributeArray(string key, string value); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _removeFromCustomUserAttributeArray(string key, string value); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserFacebookData(string facebookId, string firstName, string lastName, string email, string bio, string cityName, int gender, int numberOfFriends, string birthday); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setUserTwitterData(int twitterUserId, string twitterHandle, string name, string description, int followerCount, int followingCount, int tweetCount, string profileImageUrl); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logInAppMessageClicked(string inAppMessageJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logInAppMessageImpression(string inAppMessageJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logCardImpression(string cardJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logCardClicked(string cardJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _requestFeedRefresh(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _requestFeedRefreshFromCache(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logFeedDisplayed(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logContentCardImpression(string cardJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logContentCardClicked(string cardJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logContentCardDismissed(string cardJSONString); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _requestContentCardsRefresh(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _requestContentCardsRefreshFromCache(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _logContentCardsDisplayed(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _displayNextInAppMessage(bool withDelegate); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _wipeData(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _enableSDK(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _disableSDK(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _setAttributionData(string network, string campaign, string adgroup, string creative); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _requestGeofences(decimal latitude, decimal longitude); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _requestImmediateDataFlush(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern string _getInstallTrackingId(); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _registerAppboyPushMessages(string registrationTokenBase64); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _promptUserForPushPermissions(bool provisional); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _addAlias(string label, string alias); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _configureListener(int messageType, string gameobject, string method); - - [System.Runtime.InteropServices.DllImport("__Internal")] - private static extern void _configureInternalListener(int messageType); - - public static void LogCustomEvent(string eventName) { - _logCustomEvent(eventName, null); - } - - public static void LogCustomEvent(string eventName, Dictionary properties) { - var propertiesString = Json.Serialize(properties); - _logCustomEvent(eventName, propertiesString); - } - - public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity) { - _logPurchase(productId, currencyCode, price.ToString(), quantity, null); - } - - public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary properties) { - var propertiesString = Json.Serialize(properties); - _logPurchase(productId, currencyCode, price.ToString(), quantity, propertiesString); - } - - /// - /// When you first start using Braze on a device, the user is considered "anonymous". You can use this - /// method to optionally identify a user with a unique ID. - /// - /// - public static void ChangeUser(string userId) { - _changeUser(userId); - } - - public static void SetUserFirstName(string firstName) { - _setUserFirstName(firstName); - } - - public static void SetUserLastName(string lastName) { - _setUserLastName(lastName); - } - - public static void SetUserEmail(string email) { - _setUserEmail(email); - } - - public static void SetUserGender(Gender gender) { - _setUserGender((int)gender); - } - - public static void SetUserDateOfBirth(int year, int month, int day) { - _setUserDateOfBirth(year, month, day); - } - - public static void SetUserCountry(string country) { - _setUserCountry(country); - } - - public static void SetUserHomeCity(string city) { - _setUserHomeCity(city); - } - - /// - /// Configures the user's opt-in status for email within Braze. - /// - /// - public static void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType) { - _setUserEmailNotificationSubscriptionType((int)emailNotificationSubscriptionType); - } - - /// - /// Configures the user's opt-in status for push within Braze. - /// - /// - public static void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType) { - _setUserPushNotificationSubscriptionType((int)pushNotificationSubscriptionType); - } - - public static void SetUserPhoneNumber(string phoneNumber) { - _setUserPhoneNumber(phoneNumber); - } - - public static void SetUserAvatarImageURL(string imageURL) { - _setUserAvatarImageURL(imageURL); - } - - public static void SetCustomUserAttribute(string key, bool value) { - _setCustomUserAttributeBool(key, value); - } - - public static void SetCustomUserAttribute(string key, int value) { - _setCustomUserAttributeInt(key, value); - } - - public static void SetCustomUserAttribute(string key, float value) { - _setCustomUserAttributeFloat(key, value); - } - - public static void SetCustomUserAttribute(string key, string value) { - _setCustomUserAttributeString(key, value); - } - - public static void SetCustomUserAttributeToNow(string key) { - _setCustomUserAttributeToNow(key); - } - - public static void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch) { - _setCustomUserAttributeToSecondsFromEpoch(key, secondsFromEpoch); - } - - public static void UnsetCustomUserAttribute(string key) { - _unsetCustomUserAttribute(key); - } - - public static void IncrementCustomUserAttribute(string key, int incrementValue) { - _incrementCustomUserAttribute(key, incrementValue); - } - - public static void SetCustomUserAttributeArray(string key, List array, int size) { - if (array == null) { - _setCustomUserAttributeArray(key, null, size); - } else { - _setCustomUserAttributeArray(key, array.ToArray(), size); - } - } - - public static void AddToCustomUserAttributeArray(string key, string value) { - _addToCustomUserAttributeArray(key, value); - } - - public static void RemoveFromCustomUserAttributeArray(string key, string value) { - _removeFromCustomUserAttributeArray(key, value); - } - - public static void setUserFacebookData(string facebookId, string firstName, string lastName, string email, string bio, string cityName, Gender? gender, int? numberOfFriends, string birthday) { - _setUserFacebookData(facebookId, firstName, lastName, email, bio, cityName, gender == null ? -1 : (int)gender, numberOfFriends == null ? -1 : (int)numberOfFriends, birthday); - } - - public static void setUserTwitterData(int? twitterUserId, string twitterHandle, string name, string description, int? followerCount, int? followingCount, int? tweetCount, string profileImageUrl) { - _setUserTwitterData(twitterUserId == null ? -1 : (int)twitterUserId, twitterHandle, name, description, followerCount == null ? -1 : (int)followerCount, followingCount == null ? -1 : (int)followingCount, tweetCount == null ? -1 : (int)tweetCount, profileImageUrl); - } - - public static void DisplayNextInAppMessage(bool withDelegate) { - _displayNextInAppMessage(withDelegate); - } - - public static void LogInAppMessageClicked(string inAppMessageJSONString) { - _logInAppMessageClicked(inAppMessageJSONString); - } - - public static void LogInAppMessageImpression(string inAppMessageJSONString) { - _logInAppMessageImpression(inAppMessageJSONString); - } - - public static void LogInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID) { - _logInAppMessageButtonClicked(inAppMessageJSONString, buttonID); - } - - public static void LogCardImpression(string cardJSONString) { - _logCardImpression(cardJSONString); - } - - public static void LogCardClicked(string cardJSONString) { - _logCardClicked(cardJSONString); - } - - public static void RequestFeedRefresh() { - _requestFeedRefresh(); - } - - public static void RequestFeedRefreshFromCache() { - _requestFeedRefreshFromCache(); - } - - public static void LogFeedDisplayed() { - _logFeedDisplayed(); - } - - public static void LogContentCardImpression(string cardJSONString) { - _logContentCardImpression(cardJSONString); - } - - public static void LogContentCardClicked(string cardJSONString) { - _logContentCardClicked(cardJSONString); - } - - public static void LogContentCardDismissed(string cardJSONString) { - _logContentCardDismissed(cardJSONString); - } - - public static void RequestContentCardsRefresh() { - _requestContentCardsRefresh(); - } - - public static void RequestContentCardsRefreshFromCache() { - _requestContentCardsRefreshFromCache(); - } - - public static void LogContentCardsDisplayed() { - _logContentCardsDisplayed(); - } - - public static void WipeData() { - _wipeData(); - } - - public static void EnableSDK() { - _enableSDK(); - } - - public static void DisableSDK() { - _disableSDK(); - } - - public static string GetInstallTrackingId() { - return _getInstallTrackingId(); - } - - public static void SetAttributionData(string network, string campaign, string adgroup, string creative) { - _setAttributionData(network, campaign, adgroup, creative); - } - - public static void RequestLocationInitialization() { - // no-op - } - - /// - /// Registers a device token (the term for push token on iOS) with Braze. - /// - /// - /// The device token - /// - public static void RegisterAppboyPushMessages(byte[] registrationDeviceToken) { - string registrationTokenBase64 = Convert.ToBase64String(registrationDeviceToken); - _registerAppboyPushMessages(registrationTokenBase64); - } - - /// - /// Prompts the user for push permissions and registers the user to receive push notifications. - /// - /// To subscribe to the result, set a Game Object to listen for - /// events using - /// , or pass in a delegate instance of . - /// - /// - /// If set to true, on iOS 12 and above, the user will be provisionally (silently) authorized - /// to receive quiet push. - /// Otherwise, the user will be shown the native push prompt. - /// - /// - /// An optional delegate instance to receive the user's response to the prompt. - /// - public static void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived reponseDelegate = null) { - if (reponseDelegate != null) { - _configureInternalListener((int)BrazeUnityMessageType.PUSH_PERMISSIONS_PROMPT_RESPONSE); - BrazeInternalGameObject.setPushPromptResponseReceivedDelegate(reponseDelegate); - } - _promptUserForPushPermissions(provisional); - } - - /// - /// Configures Braze to send push tokens from the OS to the provided delegate. Braze will only listen for push tokens - /// from the OS if automatic push registration is enabled. - /// - /// Tokens passed to Braze via will also cause the delegate to be called. - /// - /// - /// A delegate instance to receive push tokens. - /// - public static void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate) { - if (tokenDelegate == null) { - return; - } - BrazeInternalGameObject.setPushTokenReceivedFromSystemDelegate(tokenDelegate); - _configureInternalListener((int)BrazeUnityMessageType.PUSH_TOKEN_RECEIVED_FROM_SYSTEM); - } - - /// - /// Requests a refresh of Braze Geofences for the specified GPS coordinate. - /// - /// - /// A valid GPS latitude in range (-90, 90). - /// - /// - /// A valid GPS longitude in range (-180, 180). - /// - /// - public static void RequestGeofences(decimal latitude, decimal longitude) { - _requestGeofences(latitude, longitude); - } - - public static void RequestImmediateDataFlush() { - _requestImmediateDataFlush(); - } - - public static void AddAlias(string alias, string label) { - _addAlias(alias, label); - } - - /// - /// Used to configure Braze to send messages to GameObjects based - /// on lifecycle events. See for - /// available message types. - /// - /// Any previous configured game object callback will be overwritten. - /// There can only be one active callback per message type. - /// - /// - /// The type of message to send to the target GameObject. - /// - /// - /// The target GameObject. - /// - /// - /// The script method to call on the GameObject. - /// - public static void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method) { - _configureListener((int)messageType, gameobject, method); - } - -#elif UNITY_ANDROID - private static AndroidJavaObject appboyUnityActivity; - private static AndroidJavaObject inAppMessageUtils; - private static AndroidJavaObject appboyLocationService; - private static AndroidJavaObject unityConfigurationProvider; - - void Start() { - Debug.Log("Starting Braze binding for Android clients."); - } - - #region Properties - public static AndroidJavaObject AppboyUnityActivity { - get { - if (appboyUnityActivity == null) { - using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { - appboyUnityActivity = unityPlayer.GetStatic("currentActivity"); - } - } - return appboyUnityActivity; - } - } - - public static AndroidJavaObject Appboy { - get { - using (var appboyClass = new AndroidJavaClass("com.appboy.Appboy")) { - return appboyClass.CallStatic("getInstance", AppboyUnityActivity); - } - } - } - - public static AndroidJavaObject InAppMessageUtils { - get { - if (inAppMessageUtils == null) { - inAppMessageUtils = new AndroidJavaClass("com.appboy.unity.utils.InAppMessageUtils"); - } - return inAppMessageUtils; - } - } - - public static AndroidJavaObject AppboyLocationService { - get { - if (appboyLocationService == null) { - appboyLocationService = new AndroidJavaClass("com.appboy.services.AppboyLocationService"); - } - return appboyLocationService; - } - } + public delegate void PushPromptResponseReceived(bool granted); + public delegate void PushTokenReceivedFromSystem(string token); - public static AndroidJavaObject UnityConfigurationProvider { - get { - if (unityConfigurationProvider == null) { - unityConfigurationProvider = new AndroidJavaObject("com.appboy.unity.configuration.UnityConfigurationProvider", AppboyUnityActivity); - } - return unityConfigurationProvider; + public class AppboyBinding : MonoBehaviour { + public static BrazePlatform mBinding { + get { + #if UNITY_ANDROID + return new BrazeAndroidPlatform(); + #elif UNITY_IOS + return new BrazeiOSPlatform(); + #endif } } - #endregion - - private static AndroidJavaObject GetCurrentUser() { - return Appboy.Call("getCurrentUser"); - } - public static void LogCustomEvent(string eventName) { - Appboy.Call("logCustomEvent", eventName); - } - - public static AndroidJavaObject ParsePropertiesToAppboyProperties(Dictionary properties) { - AndroidJavaObject appboyProperties = new AndroidJavaObject("com.appboy.models.outgoing.AppboyProperties"); - if (properties != null && properties.Count > 0) { - foreach (KeyValuePair entry in properties) { - if (entry.Value == null) { - continue; - } - - // Public API only supports int/string/double/bool/DateTime. Other values can't get mapped - // to Android AppboyProperty methods without casting. - if (entry.Value.GetType() == typeof(int) || entry.Value.GetType() == typeof(string) || - entry.Value.GetType() == typeof(double) || entry.Value.GetType() == typeof(bool)) { - appboyProperties.Call("addProperty", entry.Key, entry.Value); - } else { - appboyProperties.Call("addProperty", entry.Key, entry.Value.ToString()); - } - } - } - return appboyProperties; + #if HAS_BRAZE_SDK + mBinding.LogCustomEvent(eventName); + #endif } /// @@ -668,19 +107,32 @@ public static AndroidJavaObject ParsePropertiesToAppboyProperties(Dictionary public static void LogCustomEvent(string eventName, Dictionary properties) { - AndroidJavaObject appboyProperties = ParsePropertiesToAppboyProperties(properties); - Appboy.Call("logCustomEvent", eventName, appboyProperties); + #if HAS_BRAZE_SDK + mBinding.LogCustomEvent(eventName, properties); + #endif + } + + // Overload + public static void LogPurchase(string productId, string currencyCode, decimal price) { + LogPurchase(productId, currencyCode, price, 1); } public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity) { - var javaPrice = new AndroidJavaObject("java.math.BigDecimal", price.ToString()); - Appboy.Call("logPurchase", productId, currencyCode, javaPrice, quantity); + #if HAS_BRAZE_SDK + mBinding.LogPurchase(productId, currencyCode, price, quantity); + #endif } - public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary properties) { - var javaPrice = new AndroidJavaObject("java.math.BigDecimal", price.ToString()); - AndroidJavaObject appboyProperties = ParsePropertiesToAppboyProperties(properties); - Appboy.Call("logPurchase", productId, currencyCode, javaPrice, quantity, appboyProperties); + public static void LogPurchase( + string productId, + string currencyCode, + decimal price, + int quantity, + Dictionary properties + ) { + #if HAS_BRAZE_SDK + mBinding.LogPurchase(productId, currencyCode, price, quantity, properties); + #endif } /// @@ -689,19 +141,27 @@ public static void LogPurchase(string productId, string currencyCode, decimal pr /// /// public static void ChangeUser(string userId) { - Appboy.Call("changeUser", userId); + #if HAS_BRAZE_SDK + mBinding.ChangeUser(userId); + #endif } public static void SetUserFirstName(string firstName) { - GetCurrentUser().Call("setFirstName", firstName); + #if HAS_BRAZE_SDK + mBinding.SetUserFirstName(firstName); + #endif } public static void SetUserLastName(string lastName) { - GetCurrentUser().Call("setLastName", lastName); + #if HAS_BRAZE_SDK + mBinding.SetUserLastName(lastName); + #endif } public static void SetUserEmail(string email) { - GetCurrentUser().Call("setEmail", email); + #if HAS_BRAZE_SDK + mBinding.SetUserEmail(email); + #endif } /// @@ -711,33 +171,12 @@ public static void SetUserEmail(string email) { /// The gender of the user. See `Appboy/models/Gender.cs` for options. /// public static void SetUserGender(Gender gender) { - using (var genderClass = new AndroidJavaClass("com.appboy.enums.Gender")) { - switch (gender) { - case Gender.Male: - GetCurrentUser().Call("setGender", genderClass.GetStatic("MALE")); - break; - case Gender.Female: - GetCurrentUser().Call("setGender", genderClass.GetStatic("FEMALE")); - break; - case Gender.Other: - GetCurrentUser().Call("setGender", genderClass.GetStatic("OTHER")); - break; - case Gender.Unknown: - GetCurrentUser().Call("setGender", genderClass.GetStatic("UNKNOWN")); - break; - case Gender.NotApplicable: - GetCurrentUser().Call("setGender", genderClass.GetStatic("NOT_APPLICABLE")); - break; - case Gender.PreferNotToSay: - GetCurrentUser().Call("setGender", genderClass.GetStatic("PREFER_NOT_TO_SAY")); - break; - default: - Debug.Log("Unknown gender received: " + gender); - break; - } - } + #if HAS_BRAZE_SDK + mBinding.SetUserGender(gender); + #endif } + /// /// Sets the date of birth for the current user. /// @@ -751,59 +190,21 @@ public static void SetUserGender(Gender gender) { /// Ordinal for the day of the month. /// public static void SetUserDateOfBirth(int year, int month, int day) { - using (var monthClass = new AndroidJavaClass("com.appboy.enums.Month")) { - AndroidJavaObject monthObject; - switch (month) { - case 1: - monthObject = monthClass.GetStatic("JANUARY"); - break; - case 2: - monthObject = monthClass.GetStatic("FEBRUARY"); - break; - case 3: - monthObject = monthClass.GetStatic("MARCH"); - break; - case 4: - monthObject = monthClass.GetStatic("APRIL"); - break; - case 5: - monthObject = monthClass.GetStatic("MAY"); - break; - case 6: - monthObject = monthClass.GetStatic("JUNE"); - break; - case 7: - monthObject = monthClass.GetStatic("JULY"); - break; - case 8: - monthObject = monthClass.GetStatic("AUGUST"); - break; - case 9: - monthObject = monthClass.GetStatic("SEPTEMBER"); - break; - case 10: - monthObject = monthClass.GetStatic("OCTOBER"); - break; - case 11: - monthObject = monthClass.GetStatic("NOVEMBER"); - break; - case 12: - monthObject = monthClass.GetStatic("DECEMBER"); - break; - default: - Debug.Log("Month must be in range from 1-12"); - return; - } - GetCurrentUser().Call("setDateOfBirth", year, monthObject, day); - } + #if HAS_BRAZE_SDK + mBinding.SetUserDateOfBirth(year, month, day); + #endif } public static void SetUserCountry(string country) { - GetCurrentUser().Call("setCountry", country); + #if HAS_BRAZE_SDK + mBinding.SetUserCountry(country); + #endif } public static void SetUserHomeCity(string city) { - GetCurrentUser().Call("setHomeCity", city); + #if HAS_BRAZE_SDK + mBinding.SetUserHomeCity(city); + #endif } /// @@ -811,22 +212,9 @@ public static void SetUserHomeCity(string city) { /// /// public static void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType) { - using (var notificationTypeClass = new AndroidJavaClass("com.appboy.enums.NotificationSubscriptionType")) { - switch (emailNotificationSubscriptionType) { - case AppboyNotificationSubscriptionType.OPTED_IN: - GetCurrentUser().Call("setEmailNotificationSubscriptionType", notificationTypeClass.GetStatic("OPTED_IN")); - break; - case AppboyNotificationSubscriptionType.SUBSCRIBED: - GetCurrentUser().Call("setEmailNotificationSubscriptionType", notificationTypeClass.GetStatic("SUBSCRIBED")); - break; - case AppboyNotificationSubscriptionType.UNSUBSCRIBED: - GetCurrentUser().Call("setEmailNotificationSubscriptionType", notificationTypeClass.GetStatic("UNSUBSCRIBED")); - break; - default: - Debug.Log("Unknown notification subscription type received: " + emailNotificationSubscriptionType); - break; - } - } + #if HAS_BRAZE_SDK + mBinding.SetUserEmailNotificationSubscriptionType(emailNotificationSubscriptionType); + #endif } /// @@ -834,228 +222,323 @@ public static void SetUserEmailNotificationSubscriptionType(AppboyNotificationSu /// /// public static void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType) { - using (var notificationTypeClass = new AndroidJavaClass("com.appboy.enums.NotificationSubscriptionType")) { - switch (pushNotificationSubscriptionType) { - case AppboyNotificationSubscriptionType.OPTED_IN: - GetCurrentUser().Call("setPushNotificationSubscriptionType", notificationTypeClass.GetStatic("OPTED_IN")); - break; - case AppboyNotificationSubscriptionType.SUBSCRIBED: - GetCurrentUser().Call("setPushNotificationSubscriptionType", notificationTypeClass.GetStatic("SUBSCRIBED")); - break; - case AppboyNotificationSubscriptionType.UNSUBSCRIBED: - GetCurrentUser().Call("setPushNotificationSubscriptionType", notificationTypeClass.GetStatic("UNSUBSCRIBED")); - break; - default: - Debug.Log("Unknown notification subscription type received: " + pushNotificationSubscriptionType); - break; - } - } + #if HAS_BRAZE_SDK + mBinding.SetUserPushNotificationSubscriptionType(pushNotificationSubscriptionType); + #endif } public static void SetUserPhoneNumber(string phoneNumber) { - GetCurrentUser().Call("setPhoneNumber", phoneNumber); + #if HAS_BRAZE_SDK + mBinding.SetUserPhoneNumber(phoneNumber); + #endif } public static void SetUserAvatarImageURL(string imageURL) { - GetCurrentUser().Call("setAvatarImageUrl", imageURL); + #if HAS_BRAZE_SDK + mBinding.SetUserAvatarImageURL(imageURL); + #endif } public static void SetCustomUserAttribute(string key, bool value) { - GetCurrentUser().Call("setCustomUserAttribute", key, value); + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttribute(key, value); + #endif } public static void SetCustomUserAttribute(string key, int value) { - GetCurrentUser().Call("setCustomUserAttribute", key, value); + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttribute(key, value); + #endif } public static void SetCustomUserAttribute(string key, float value) { - GetCurrentUser().Call("setCustomUserAttribute", key, value); + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttribute(key, value); + #endif } public static void SetCustomUserAttribute(string key, string value) { - GetCurrentUser().Call("setCustomUserAttribute", key, value); + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttribute(key, value); + #endif } public static void SetCustomUserAttributeToNow(string key) { - GetCurrentUser().Call("setCustomUserAttributeToNow", key); + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttributeToNow(key); + #endif } public static void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch) { - GetCurrentUser().Call("setCustomUserAttributeToSecondsFromEpoch", key, secondsFromEpoch); + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttributeToSecondsFromEpoch(key, secondsFromEpoch); + #endif } public static void UnsetCustomUserAttribute(string key) { - GetCurrentUser().Call("unsetCustomUserAttribute", key); + #if HAS_BRAZE_SDK + mBinding.UnsetCustomUserAttribute(key); + #endif + } + + // Overload + public static void IncrementCustomUserAttribute(string key) { + IncrementCustomUserAttribute(key, 1); } public static void IncrementCustomUserAttribute(string key, int incrementValue) { - GetCurrentUser().Call("incrementCustomUserAttribute", key, incrementValue); + #if HAS_BRAZE_SDK + mBinding.IncrementCustomUserAttribute(key, incrementValue); + #endif } public static void SetCustomUserAttributeArray(string key, List array, int size) { - if (array == null) { - GetCurrentUser().Call("setCustomAttributeArray", key, null); - } else { - GetCurrentUser().Call("setCustomAttributeArray", key, array.ToArray()); - } + #if HAS_BRAZE_SDK + mBinding.SetCustomUserAttributeArray(key, array, size); + #endif } public static void AddToCustomUserAttributeArray(string key, string value) { - GetCurrentUser().Call("addToCustomAttributeArray", key, value); + #if HAS_BRAZE_SDK + mBinding.AddToCustomUserAttributeArray(key, value); + #endif } - public static void setUserFacebookData(string facebookId, string firstName, string lastName, string email, string bio, string cityName, Gender? gender, int? numberOfFriends, string birthday) { - var genderClass = new AndroidJavaClass("com.appboy.enums.Gender"); - AndroidJavaObject genderEnum = null; - if (gender != null) { - switch (gender) { - case Gender.Male: - genderEnum = genderClass.GetStatic("MALE"); - break; - case Gender.Female: - genderEnum = genderClass.GetStatic("FEMALE"); - break; - default: - Debug.Log("Unknown gender received: " + gender); - break; - } + public static void RemoveFromCustomUserAttributeArray(string key, string value) { + #if HAS_BRAZE_SDK + mBinding.RemoveFromCustomUserAttributeArray(key, value); + #endif + } + + public static void setUserFacebookData( + string facebookId, + string firstName, + string lastName, + string email, + string bio, + string cityName, + Gender? gender, + int? numberOfFriends, + string birthday + ) { + #if HAS_BRAZE_SDK + mBinding.setUserFacebookData(facebookId, firstName, lastName, email, bio, cityName, gender, numberOfFriends, birthday); + #endif + } + + public static void setUserTwitterData( + int? twitterUserId, + string twitterHandle, + string name, + string description, + int? followerCount, + int? followingCount, + int? tweetCount, + string profileImageUrl + ) { + #if HAS_BRAZE_SDK + mBinding.setUserTwitterData(twitterUserId, twitterHandle, name, description, followerCount, followingCount, tweetCount, profileImageUrl); + #endif + } + + #if UNITY_ANDROID + + /// + /// Registers a push token with Braze. + /// + /// + /// The push token + /// + public static void RegisterAppboyPushMessages(string registrationId) { + #if UNITY_ANDROID + mBinding.RegisterAppboyPushMessages(registrationId); + #endif } - var facebookUser = new AndroidJavaObject("com.appboy.models.outgoing.FacebookUser", new object[] - { - facebookId, - firstName, - lastName, - email, - bio, - cityName, - genderEnum, - numberOfFriends == null ? null : new AndroidJavaObject("java.lang.Integer", numberOfFriends), - null, - birthday - } - ); - - GetCurrentUser().Call("setFacebookData", facebookUser); - } - - public static void setUserTwitterData(int? twitterUserId, string twitterHandle, string name, string description, int? followerCount, int? followingCount, int? tweetCount, string profileImageUrl) { - var twitterUser = new AndroidJavaObject("com.appboy.models.outgoing.TwitterUser", new object[] - { - twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", twitterUserId), - twitterHandle, - name, - description, - twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", followerCount), - twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", followingCount), - twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", tweetCount), - profileImageUrl - } - ); - GetCurrentUser().Call("setTwitterData", twitterUser); - } + #elif UNITY_IOS + + /// + /// Registers a push token with Braze. + /// + /// + /// The push token + /// + public static void RegisterAppboyPushMessages(byte[] registrationDeviceToken) { + #if UNITY_IOS + mBinding.RegisterAppboyPushMessages(registrationDeviceToken); + #endif + } - public static void RemoveFromCustomUserAttributeArray(string key, string value) { - GetCurrentUser().Call("removeFromCustomAttributeArray", key, value); - } + #endif /// - /// Registers a push token with Braze. + /// Prompts the user for push permissions and registers the user to receive push notifications. + /// + /// To subscribe to the result, set a Game Object to listen for + /// events using + /// , or pass in a delegate instance of . /// - /// - /// The push token + /// + /// If set to true, on iOS 12 and above, the user will be provisionally (silently) authorized + /// to receive quiet push. + /// Otherwise, the user will be shown the native push prompt. /// - public static void RegisterAppboyPushMessages(string registrationId) { - Appboy.Call("registerAppboyPushMessages", new object[] { registrationId }); + /// + /// An optional delegate instance to receive the user's response to the prompt. + /// + public static void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived responseDelegate = null) { + #if HAS_BRAZE_SDK + mBinding.PromptUserForPushPermissions(provisional, responseDelegate); + #endif } /// - /// No-op on Android. - /// - /// + /// Configures Braze to send push tokens from the OS to the provided delegate. Braze will only listen for push tokens + /// from the OS if automatic push registration is enabled. + /// + /// Tokens passed to Braze via will also cause the delegate to be called. /// - public static void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived reponseDelegate = null) {} - - /// - /// No-op on Android. - /// /// + /// A delegate instance to receive push tokens. /// - public static void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate) {} + public static void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate) { + #if HAS_BRAZE_SDK + mBinding.SetPushTokenReceivedFromSystemDelegate(tokenDelegate); + #endif + } public static void LogInAppMessageClicked(string inAppMessageJSONString) { - var inAppMessage = InAppMessageUtils.CallStatic("inAppMessageFromString", appboyUnityActivity, inAppMessageJSONString); - InAppMessageUtils.CallStatic("logInAppMessageClick", inAppMessage); + #if HAS_BRAZE_SDK + mBinding.LogInAppMessageClicked(inAppMessageJSONString); + #endif } public static void LogInAppMessageImpression(string inAppMessageJSONString) { - var inAppMessage = InAppMessageUtils.CallStatic("inAppMessageFromString", appboyUnityActivity, inAppMessageJSONString); - InAppMessageUtils.CallStatic("logInAppMessageImpression", inAppMessage); + #if HAS_BRAZE_SDK + mBinding.LogInAppMessageImpression(inAppMessageJSONString); + #endif } public static void LogInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID) { - var inAppMessage = InAppMessageUtils.CallStatic("inAppMessageFromString", appboyUnityActivity, inAppMessageJSONString); - InAppMessageUtils.CallStatic("logInAppMessageButtonClick", inAppMessage, buttonID); + #if HAS_BRAZE_SDK + mBinding.LogInAppMessageButtonClicked(inAppMessageJSONString, buttonID); + #endif } public static void RequestFeedRefresh() { - Appboy.Call("requestFeedRefresh"); + #if HAS_BRAZE_SDK + mBinding.RequestFeedRefresh(); + #endif } public static void RequestFeedRefreshFromCache() { - Appboy.Call("requestFeedRefreshFromCache"); + #if HAS_BRAZE_SDK + mBinding.RequestFeedRefreshFromCache(); + #endif } public static void LogFeedDisplayed() { - Appboy.Call("logFeedDisplayed"); + #if HAS_BRAZE_SDK + mBinding.LogFeedDisplayed(); + #endif } - public static void LogContentCardImpression(string contentCardString) { - var contentCard = Appboy.Call("deserializeContentCard", contentCardString); - contentCard.Call("logImpression"); - } + #if UNITY_ANDROID - public static void LogContentCardClicked(string contentCardString) { - var contentCard = Appboy.Call("deserializeContentCard", contentCardString); - contentCard.Call("logClick"); + public static void LogCardImpression(string cardId) { + #if HAS_BRAZE_SDK + mBinding.LogCardImpression(cardId); + #endif + } + + public static void LogCardClicked(string cardId) { + #if HAS_BRAZE_SDK + mBinding.LogCardClicked(cardId); + #endif + } + + #elif UNITY_IOS + + public static void LogCardImpression(string cardJSONString) { + #if HAS_BRAZE_SDK + mBinding.LogCardImpression(cardJSONString); + #endif + } + + public static void LogCardClicked(string cardJSONString) { + #if HAS_BRAZE_SDK + mBinding.LogCardClicked(cardJSONString); + #endif + } + + #endif + + public static void RequestContentCardsRefresh() { + #if HAS_BRAZE_SDK + mBinding.RequestContentCardsRefresh(); + #endif } - public static void LogContentCardDismissed(string contentCardString) { - var contentCard = Appboy.Call("deserializeContentCard", contentCardString); - contentCard.Call("setIsDismissed", true); + public static void RequestContentCardsRefreshFromCache() { + #if HAS_BRAZE_SDK + mBinding.RequestContentCardsRefreshFromCache(); + #endif } public static void LogContentCardsDisplayed() { - Appboy.Call("logContentCardsDisplayed"); + #if HAS_BRAZE_SDK + mBinding.LogContentCardsDisplayed(); + #endif } - public static void RequestContentCardsRefresh() { - Appboy.Call("requestContentCardsRefresh", false); + public static void LogContentCardClicked(string contentCardString) { + #if HAS_BRAZE_SDK + mBinding.LogContentCardClicked(contentCardString); + #endif } - public static void RequestContentCardsRefreshFromCache() { - Appboy.Call("requestContentCardsRefresh", true); + public static void LogContentCardImpression(string contentCardString) { + #if HAS_BRAZE_SDK + mBinding.LogContentCardImpression(contentCardString); + #endif + } + + public static void LogContentCardDismissed(string contentCardString) { + #if HAS_BRAZE_SDK + mBinding.LogContentCardDismissed(contentCardString); + #endif } public static void WipeData() { - Appboy.CallStatic("wipeData", appboyUnityActivity); + #if HAS_BRAZE_SDK + mBinding.WipeData(); + #endif } public static void EnableSDK() { - Appboy.CallStatic("enableSdk", appboyUnityActivity); + #if HAS_BRAZE_SDK + mBinding.EnableSDK(); + #endif } public static void DisableSDK() { - Appboy.CallStatic("disableSdk", appboyUnityActivity); + #if HAS_BRAZE_SDK + mBinding.DisableSDK(); + #endif } public static string GetInstallTrackingId() { - return Appboy.Call("getInstallTrackingId"); + #if HAS_BRAZE_SDK + return mBinding.GetInstallTrackingId(); + #else + return null; + #endif } public static void SetAttributionData(string network, string campaign, string adgroup, string creative) { - var attributionData = new AndroidJavaObject("com.appboy.models.outgoing.AttributionData", network, campaign, adgroup, creative); - GetCurrentUser().Call("setAttributionData", attributionData); + #if HAS_BRAZE_SDK + mBinding.SetAttributionData(network, campaign, adgroup, creative); + #endif } /// @@ -1063,7 +546,9 @@ public static void SetAttributionData(string network, string campaign, string ad /// initialization of Braze geofences and also request a single location update. /// public static void RequestLocationInitialization() { - AppboyLocationService.CallStatic("requestInitialization", appboyUnityActivity); + #if HAS_BRAZE_SDK + mBinding.RequestLocationInitialization(); + #endif } /// @@ -1077,15 +562,21 @@ public static void RequestLocationInitialization() { /// /// public static void RequestGeofences(decimal latitude, decimal longitude) { - Appboy.Call("requestGeofences", latitude, longitude); + #if HAS_BRAZE_SDK + mBinding.RequestGeofences(latitude, longitude); + #endif } public static void RequestImmediateDataFlush() { - Appboy.Call("requestImmediateDataFlush"); + #if HAS_BRAZE_SDK + mBinding.RequestImmediateDataFlush(); + #endif } public static void AddAlias(string alias, string label) { - GetCurrentUser().Call("addAlias", alias, label); + #if HAS_BRAZE_SDK + mBinding.AddAlias(alias, label); + #endif } /// @@ -1103,90 +594,9 @@ public static void AddAlias(string alias, string label) { /// The script method to call on the GameObject. /// public static void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method) { - UnityConfigurationProvider.Call("configureListener", (int)messageType, gameobject, method); - } - -#else - - // Empty implementations of the API, in case the application is being compiled for a platform other than iOS or Android. - void Start() { - Debug.Log("Starting no-op Braze binding for non iOS/Android clients."); - } - - public static void LogCustomEvent(string eventName) {} - public static void LogCustomEvent(string eventName, Dictionary properties) {} - public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity) {} - public static void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary properties) {} - - public static void ChangeUser(string userId) {} - - public static void SetUserFirstName(string firstName) {} - public static void SetUserLastName(string lastName) {} - public static void SetUserEmail(string email) {} - public static void SetUserGender(Gender gender) {} - public static void SetUserDateOfBirth(int year, int month, int day) {} - public static void SetUserCountry(string country) {} - public static void SetUserHomeCity(string city) {} - public static void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType) {} - public static void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType) {} - public static void SetUserPhoneNumber(string phoneNumber) {} - public static void SetUserAvatarImageURL(string imageURL) {} - - public static void SetCustomUserAttribute(string key, bool value) {} - public static void SetCustomUserAttribute(string key, int value) {} - public static void SetCustomUserAttribute(string key, float value) {} - public static void SetCustomUserAttribute(string key, string value) {} - public static void SetCustomUserAttributeToNow(string key) {} - public static void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch) {} - public static void UnsetCustomUserAttribute(string key) {} - public static void IncrementCustomUserAttribute(string key, int incrementValue) {} - public static void SetCustomUserAttributeArray(string key, List array, int size) {} - public static void AddToCustomUserAttributeArray(string key, string value) {} - public static void RemoveFromCustomUserAttributeArray(string key, string value) {} - - public static void setUserFacebookData(string facebookId, string firstName, string lastName, string email, - string bio, string cityName, Gender? gender, int? numberOfFriends, string birthday) {} - - public static void setUserTwitterData(int? twitterUserId, string twitterHandle, string name, string description, int? followerCount, - int? followingCount, int? tweetCount, string profileImageUrl) {} - - public static void RegisterAppboyPushMessages(string registrationId) {} - public static void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived reponseDelegate = null) {} - public static void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate) {} - - public static void LogInAppMessageClicked(string inAppMessageJSONString) {} - public static void LogInAppMessageImpression(string inAppMessageJSONString) {} - public static void LogInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID) {} - - public static void RequestFeedRefresh() {} - public static void RequestFeedRefreshFromCache() {} - public static void LogFeedDisplayed() {} - - public static void RequestContentCardsRefresh() {} - public static void RequestContentCardsRefreshFromCache() {} - public static void LogContentCardsDisplayed() {} - public static void LogContentCardClicked(string contentCardString) {} - public static void LogContentCardImpression(string contentCardString) { } - public static void LogContentCardDismissed(string contentCardString) { } - - public static void WipeData() {} - public static void EnableSDK() {} - public static void DisableSDK() {} - - public static string GetInstallTrackingId() { - return null; + #if HAS_BRAZE_SDK + mBinding.ConfigureListener(messageType, gameobject, method); + #endif } - - public static void SetAttributionData(string network, string campaign, string adgroup, string creative) {} - - public static void RequestLocationInitialization() {} - public static void RequestGeofences(decimal latitude, decimal longitude) {} - - public static void RequestImmediateDataFlush() {} - - public static void AddAlias(string alias, string label) {} - - public static void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method) {} -#endif } } diff --git a/Assets/Plugins/Appboy/BrazeAndroidPlatform.cs b/Assets/Plugins/Appboy/BrazeAndroidPlatform.cs new file mode 100644 index 000000000..e0df4ea26 --- /dev/null +++ b/Assets/Plugins/Appboy/BrazeAndroidPlatform.cs @@ -0,0 +1,479 @@ +using Appboy; +using Appboy.Internal; +using Appboy.Models; +using Appboy.Utilities; +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using UnityEngine; + +#if UNITY_ANDROID + +public class BrazeAndroidPlatform : BrazePlatform { + private static AndroidJavaObject appboyUnityActivity; + private static AndroidJavaObject inAppMessageUtils; + private static AndroidJavaObject unityConfigurationProvider; + + public AndroidJavaObject AppboyUnityActivity { + get { + FlushAndroidPendingPushIntents(); + if (appboyUnityActivity == null) { + using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { + appboyUnityActivity = unityPlayer.GetStatic("currentActivity"); + } + } + return appboyUnityActivity; + } + } + + public AndroidJavaObject Appboy { + get { + FlushAndroidPendingPushIntents(); + using (var appboyClass = new AndroidJavaClass("com.appboy.Appboy")) { + return appboyClass.CallStatic("getInstance", AppboyUnityActivity); + } + } + } + + public AndroidJavaObject InAppMessageUtils { + get { + FlushAndroidPendingPushIntents(); + if (inAppMessageUtils == null) { + inAppMessageUtils = new AndroidJavaClass("com.appboy.unity.utils.InAppMessageUtils"); + } + return inAppMessageUtils; + } + } + + public AndroidJavaObject UnityConfigurationProvider { + get { + FlushAndroidPendingPushIntents(); + if (unityConfigurationProvider == null) { + unityConfigurationProvider = new AndroidJavaObject("com.appboy.unity.configuration.UnityConfigurationProvider", AppboyUnityActivity); + } + return unityConfigurationProvider; + } + } + + private AndroidJavaObject GetCurrentUser() { + FlushAndroidPendingPushIntents(); + return Appboy.Call("getCurrentUser"); + } + + /// + /// Informs the push broadcast receiver to flush any pending push intents + /// + public void FlushAndroidPendingPushIntents() { + using (var receiverClass = new AndroidJavaClass("com.appboy.unity.AppboyUnityPushBroadcastReceiver")) { + receiverClass.CallStatic("onBindingInitialized"); + } + } + + public void LogCustomEvent(string eventName) { + Appboy.Call("logCustomEvent", eventName); + } + + public static AndroidJavaObject ParsePropertiesToAppboyProperties(Dictionary properties) { + AndroidJavaObject appboyProperties = new AndroidJavaObject("com.appboy.models.outgoing.AppboyProperties"); + if (properties != null && properties.Count > 0) { + foreach (KeyValuePair entry in properties) { + if (entry.Value == null) { + continue; + } + + // Public API only supports int/string/double/bool/DateTime. Other values can't get mapped + // to Android AppboyProperty methods without casting. + if (entry.Value.GetType() == typeof(int) || entry.Value.GetType() == typeof(string) || + entry.Value.GetType() == typeof(double) || entry.Value.GetType() == typeof(bool)) { + appboyProperties.Call("addProperty", entry.Key, entry.Value); + } else { + appboyProperties.Call("addProperty", entry.Key, entry.Value.ToString()); + } + } + } + return appboyProperties; + } + + public void LogCustomEvent(string eventName, Dictionary properties) { + AndroidJavaObject appboyProperties = ParsePropertiesToAppboyProperties(properties); + Appboy.Call("logCustomEvent", eventName, appboyProperties); + } + + public void LogPurchase(string productId, string currencyCode, decimal price, int quantity) { + var javaPrice = new AndroidJavaObject("java.math.BigDecimal", price.ToString()); + Appboy.Call("logPurchase", productId, currencyCode, javaPrice, quantity); + } + + public void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary properties) { + var javaPrice = new AndroidJavaObject("java.math.BigDecimal", price.ToString()); + AndroidJavaObject appboyProperties = ParsePropertiesToAppboyProperties(properties); + Appboy.Call("logPurchase", productId, currencyCode, javaPrice, quantity, appboyProperties); + } + + public void ChangeUser(string userId) { + Appboy.Call("changeUser", userId); + } + + public void SetUserFirstName(string firstName) { + GetCurrentUser().Call("setFirstName", firstName); + } + + public void SetUserLastName(string lastName) { + GetCurrentUser().Call("setLastName", lastName); + } + + public void SetUserEmail(string email) { + GetCurrentUser().Call("setEmail", email); + } + + public void SetUserGender(Gender gender) { + using (var genderClass = new AndroidJavaClass("com.appboy.enums.Gender")) { + switch (gender) { + case Gender.Male: + GetCurrentUser().Call("setGender", genderClass.GetStatic("MALE")); + break; + case Gender.Female: + GetCurrentUser().Call("setGender", genderClass.GetStatic("FEMALE")); + break; + case Gender.Other: + GetCurrentUser().Call("setGender", genderClass.GetStatic("OTHER")); + break; + case Gender.Unknown: + GetCurrentUser().Call("setGender", genderClass.GetStatic("UNKNOWN")); + break; + case Gender.NotApplicable: + GetCurrentUser().Call("setGender", genderClass.GetStatic("NOT_APPLICABLE")); + break; + case Gender.PreferNotToSay: + GetCurrentUser().Call("setGender", genderClass.GetStatic("PREFER_NOT_TO_SAY")); + break; + default: + Debug.Log("Unknown gender received: " + gender); + break; + } + } + } + + public void SetUserDateOfBirth(int year, int month, int day) { + using (var monthClass = new AndroidJavaClass("com.appboy.enums.Month")) { + AndroidJavaObject monthObject; + switch (month) { + case 1: + monthObject = monthClass.GetStatic("JANUARY"); + break; + case 2: + monthObject = monthClass.GetStatic("FEBRUARY"); + break; + case 3: + monthObject = monthClass.GetStatic("MARCH"); + break; + case 4: + monthObject = monthClass.GetStatic("APRIL"); + break; + case 5: + monthObject = monthClass.GetStatic("MAY"); + break; + case 6: + monthObject = monthClass.GetStatic("JUNE"); + break; + case 7: + monthObject = monthClass.GetStatic("JULY"); + break; + case 8: + monthObject = monthClass.GetStatic("AUGUST"); + break; + case 9: + monthObject = monthClass.GetStatic("SEPTEMBER"); + break; + case 10: + monthObject = monthClass.GetStatic("OCTOBER"); + break; + case 11: + monthObject = monthClass.GetStatic("NOVEMBER"); + break; + case 12: + monthObject = monthClass.GetStatic("DECEMBER"); + break; + default: + Debug.Log("Month must be in range from 1-12"); + return; + } + GetCurrentUser().Call("setDateOfBirth", year, monthObject, day); + } + } + + public void SetUserCountry(string country) { + GetCurrentUser().Call("setCountry", country); + } + + public void SetUserHomeCity(string city) { + GetCurrentUser().Call("setHomeCity", city); + } + + public void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType) { + using (var notificationTypeClass = new AndroidJavaClass("com.appboy.enums.NotificationSubscriptionType")) { + switch (emailNotificationSubscriptionType) { + case AppboyNotificationSubscriptionType.OPTED_IN: + GetCurrentUser().Call("setEmailNotificationSubscriptionType", notificationTypeClass.GetStatic("OPTED_IN")); + break; + case AppboyNotificationSubscriptionType.SUBSCRIBED: + GetCurrentUser().Call("setEmailNotificationSubscriptionType", notificationTypeClass.GetStatic("SUBSCRIBED")); + break; + case AppboyNotificationSubscriptionType.UNSUBSCRIBED: + GetCurrentUser().Call("setEmailNotificationSubscriptionType", notificationTypeClass.GetStatic("UNSUBSCRIBED")); + break; + default: + Debug.Log("Unknown notification subscription type received: " + emailNotificationSubscriptionType); + break; + } + } + } + + public void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType) { + using (var notificationTypeClass = new AndroidJavaClass("com.appboy.enums.NotificationSubscriptionType")) { + switch (pushNotificationSubscriptionType) { + case AppboyNotificationSubscriptionType.OPTED_IN: + GetCurrentUser().Call("setPushNotificationSubscriptionType", notificationTypeClass.GetStatic("OPTED_IN")); + break; + case AppboyNotificationSubscriptionType.SUBSCRIBED: + GetCurrentUser().Call("setPushNotificationSubscriptionType", notificationTypeClass.GetStatic("SUBSCRIBED")); + break; + case AppboyNotificationSubscriptionType.UNSUBSCRIBED: + GetCurrentUser().Call("setPushNotificationSubscriptionType", notificationTypeClass.GetStatic("UNSUBSCRIBED")); + break; + default: + Debug.Log("Unknown notification subscription type received: " + pushNotificationSubscriptionType); + break; + } + } + } + + public void SetUserPhoneNumber(string phoneNumber) { + GetCurrentUser().Call("setPhoneNumber", phoneNumber); + } + + public void SetUserAvatarImageURL(string imageURL) { + GetCurrentUser().Call("setAvatarImageUrl", imageURL); + } + + public void SetCustomUserAttribute(string key, bool value) { + GetCurrentUser().Call("setCustomUserAttribute", key, value); + } + + public void SetCustomUserAttribute(string key, int value) { + GetCurrentUser().Call("setCustomUserAttribute", key, value); + } + + public void SetCustomUserAttribute(string key, float value) { + GetCurrentUser().Call("setCustomUserAttribute", key, value); + } + + public void SetCustomUserAttribute(string key, string value) { + GetCurrentUser().Call("setCustomUserAttribute", key, value); + } + + public void SetCustomUserAttributeToNow(string key) { + GetCurrentUser().Call("setCustomUserAttributeToNow", key); + } + + public void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch) { + GetCurrentUser().Call("setCustomUserAttributeToSecondsFromEpoch", key, secondsFromEpoch); + } + + public void UnsetCustomUserAttribute(string key) { + GetCurrentUser().Call("unsetCustomUserAttribute", key); + } + + public void IncrementCustomUserAttribute(string key, int incrementValue) { + GetCurrentUser().Call("incrementCustomUserAttribute", key, incrementValue); + } + + public void SetCustomUserAttributeArray(string key, List array, int size) { + if (array == null) { + GetCurrentUser().Call("setCustomAttributeArray", key, null); + } else { + GetCurrentUser().Call("setCustomAttributeArray", key, array.ToArray()); + } + } + + public void AddToCustomUserAttributeArray(string key, string value) { + GetCurrentUser().Call("addToCustomAttributeArray", key, value); + } + + public void setUserFacebookData(string facebookId, string firstName, string lastName, string email, string bio, string cityName, Gender? gender, int? numberOfFriends, string birthday) { + var genderClass = new AndroidJavaClass("com.appboy.enums.Gender"); + AndroidJavaObject genderEnum = null; + if (gender != null) { + switch (gender) { + case Gender.Male: + genderEnum = genderClass.GetStatic("MALE"); + break; + case Gender.Female: + genderEnum = genderClass.GetStatic("FEMALE"); + break; + default: + Debug.Log("Unknown gender received: " + gender); + break; + } + } + + var facebookUser = new AndroidJavaObject("com.appboy.models.outgoing.FacebookUser", new object[] + { + facebookId, + firstName, + lastName, + email, + bio, + cityName, + genderEnum, + numberOfFriends == null ? null : new AndroidJavaObject("java.lang.Integer", numberOfFriends), + null, + birthday + } + ); + + GetCurrentUser().Call("setFacebookData", facebookUser); + } + + public void setUserTwitterData(int? twitterUserId, string twitterHandle, string name, string description, int? followerCount, int? followingCount, int? tweetCount, string profileImageUrl) { + var twitterUser = new AndroidJavaObject("com.appboy.models.outgoing.TwitterUser", new object[] + { + twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", twitterUserId), + twitterHandle, + name, + description, + twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", followerCount), + twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", followingCount), + twitterUserId == null ? null : new AndroidJavaObject("java.lang.Integer", tweetCount), + profileImageUrl + } + ); + GetCurrentUser().Call("setTwitterData", twitterUser); + } + + public void RemoveFromCustomUserAttributeArray(string key, string value) { + GetCurrentUser().Call("removeFromCustomAttributeArray", key, value); + } + + public void RegisterAppboyPushMessages(string registrationId) { + Appboy.Call("registerAppboyPushMessages", new object[] { registrationId }); + } + + /// + /// No-op on Android. + /// + public void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived reponseDelegate = null) {} + + /// + /// No-op on Android. + /// + /// + /// + public void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate) {} + + public void LogInAppMessageClicked(string inAppMessageJSONString) { + var inAppMessage = InAppMessageUtils.CallStatic("inAppMessageFromString", appboyUnityActivity, inAppMessageJSONString); + InAppMessageUtils.CallStatic("logInAppMessageClick", inAppMessage); + } + + public void LogInAppMessageImpression(string inAppMessageJSONString) { + var inAppMessage = InAppMessageUtils.CallStatic("inAppMessageFromString", appboyUnityActivity, inAppMessageJSONString); + InAppMessageUtils.CallStatic("logInAppMessageImpression", inAppMessage); + } + + public void LogInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID) { + var inAppMessage = InAppMessageUtils.CallStatic("inAppMessageFromString", appboyUnityActivity, inAppMessageJSONString); + InAppMessageUtils.CallStatic("logInAppMessageButtonClick", inAppMessage, buttonID); + } + + public void RequestFeedRefresh() { + Appboy.Call("requestFeedRefresh"); + } + + public void RequestFeedRefreshFromCache() { + Appboy.Call("requestFeedRefreshFromCache"); + } + + public void LogFeedDisplayed() { + Appboy.Call("logFeedDisplayed"); + } + + public void LogCardImpression(string cardId) { + Appboy.Call("logFeedCardImpression", cardId); + } + + public void LogCardClicked(string cardId) { + Appboy.Call("logFeedCardClick", cardId); + } + + public void LogContentCardImpression(string contentCardString) { + var contentCard = Appboy.Call("deserializeContentCard", contentCardString); + contentCard.Call("logImpression"); + } + + public void LogContentCardClicked(string contentCardString) { + var contentCard = Appboy.Call("deserializeContentCard", contentCardString); + contentCard.Call("logClick"); + } + + public void LogContentCardDismissed(string contentCardString) { + var contentCard = Appboy.Call("deserializeContentCard", contentCardString); + contentCard.Call("setIsDismissed", true); + } + + public void LogContentCardsDisplayed() { + Appboy.Call("logContentCardsDisplayed"); + } + + public void RequestContentCardsRefresh() { + Appboy.Call("requestContentCardsRefresh", false); + } + + public void RequestContentCardsRefreshFromCache() { + Appboy.Call("requestContentCardsRefresh", true); + } + + public void WipeData() { + Appboy.CallStatic("wipeData", appboyUnityActivity); + } + + public void EnableSDK() { + Appboy.CallStatic("enableSdk", appboyUnityActivity); + } + + public void DisableSDK() { + Appboy.CallStatic("disableSdk", appboyUnityActivity); + } + + public string GetInstallTrackingId() { + return Appboy.Call("getInstallTrackingId"); + } + + public void SetAttributionData(string network, string campaign, string adgroup, string creative) { + var attributionData = new AndroidJavaObject("com.appboy.models.outgoing.AttributionData", network, campaign, adgroup, creative); + GetCurrentUser().Call("setAttributionData", attributionData); + } + + public void RequestLocationInitialization() { + Appboy.Call("requestLocationInitialization"); + } + + public void RequestGeofences(decimal latitude, decimal longitude) { + Appboy.Call("requestGeofences", latitude, longitude); + } + + public void RequestImmediateDataFlush() { + Appboy.Call("requestImmediateDataFlush"); + } + + public void AddAlias(string alias, string label) { + GetCurrentUser().Call("addAlias", alias, label); + } + + public void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method) { + UnityConfigurationProvider.Call("configureListener", (int)messageType, gameobject, method); + } +} + +#endif diff --git a/Assets/Plugins/Appboy/BrazeAndroidPlatform.cs.meta b/Assets/Plugins/Appboy/BrazeAndroidPlatform.cs.meta new file mode 100644 index 000000000..e296c4be3 --- /dev/null +++ b/Assets/Plugins/Appboy/BrazeAndroidPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dc63ef47bf9384adf98719fbe60813cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/Appboy/BrazePlatform.cs b/Assets/Plugins/Appboy/BrazePlatform.cs new file mode 100644 index 000000000..7fa00c53c --- /dev/null +++ b/Assets/Plugins/Appboy/BrazePlatform.cs @@ -0,0 +1,119 @@ +using Appboy.Internal; +using Appboy.Models; +using Appboy.Utilities; +using Appboy; +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using UnityEngine; + +public interface BrazePlatform { + void LogCustomEvent(string eventName); + void LogCustomEvent(string eventName, Dictionary properties); + void LogPurchase(string productId, + string currencyCode, + decimal price, + int quantity + ); + void LogPurchase( + string productId, + string currencyCode, + decimal price, + int quantity, + Dictionary properties + ); + + void ChangeUser(string userId); + + void SetUserFirstName(string firstName); + void SetUserLastName(string lastName); + void SetUserEmail(string email); + void SetUserGender(Gender gender); + void SetUserDateOfBirth(int year, int month, int day); + void SetUserCountry(string country); + void SetUserHomeCity(string city); + void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType); + void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType); + void SetUserPhoneNumber(string phoneNumber); + void SetUserAvatarImageURL(string imageURL); + + void SetCustomUserAttribute(string key, bool value); + void SetCustomUserAttribute(string key, int value); + void SetCustomUserAttribute(string key, float value); + void SetCustomUserAttribute(string key, string value); + void SetCustomUserAttributeToNow(string key); + void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch); + void UnsetCustomUserAttribute(string key); + void IncrementCustomUserAttribute(string key, int incrementValue); + void SetCustomUserAttributeArray(string key, List array, int size); + void AddToCustomUserAttributeArray(string key, string value); + void RemoveFromCustomUserAttributeArray(string key, string value); + + void setUserFacebookData( + string facebookId, + string firstName, + string lastName, + string email, + string bio, + string cityName, + Gender? gender, + int? numberOfFriends, + string birthday + ); + + void setUserTwitterData( + int? twitterUserId, + string twitterHandle, + string name, + string description, + int? followerCount, + int? followingCount, + int? tweetCount, + string profileImageUrl + ); + + #if UNITY_ANDROID + void RegisterAppboyPushMessages(string registrationId); + #elif UNITY_IOS + void RegisterAppboyPushMessages(byte[] registrationDeviceToken); + #endif + void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived reponseDelegate = null); + void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate); + + void LogInAppMessageClicked(string inAppMessageJSONString); + void LogInAppMessageImpression(string inAppMessageJSONString); + void LogInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID); + + void RequestFeedRefresh(); + void RequestFeedRefreshFromCache(); + void LogFeedDisplayed(); + + #if UNITY_ANDROID + void LogCardImpression(string cardId); + void LogCardClicked(string cardId); + #elif UNITY_IOS + void LogCardImpression(string cardJSONString); + void LogCardClicked(string cardJSONString); + #endif + void RequestContentCardsRefresh(); + void RequestContentCardsRefreshFromCache(); + void LogContentCardsDisplayed(); + void LogContentCardClicked(string contentCardString); + void LogContentCardImpression(string contentCardString); + void LogContentCardDismissed(string contentCardString); + + void WipeData(); + void EnableSDK(); + void DisableSDK(); + + string GetInstallTrackingId(); + void SetAttributionData(string network, string campaign, string adgroup, string creative); + + void RequestLocationInitialization(); + void RequestGeofences(decimal latitude, decimal longitude); + + void RequestImmediateDataFlush(); + void AddAlias(string alias, string label); + void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method); +} diff --git a/Assets/Plugins/Appboy/BrazePlatform.cs.meta b/Assets/Plugins/Appboy/BrazePlatform.cs.meta new file mode 100644 index 000000000..9bffe5570 --- /dev/null +++ b/Assets/Plugins/Appboy/BrazePlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7c0eae43a8bd437aa65b823dc3b85fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/Appboy/BrazeiOSPlatform.cs b/Assets/Plugins/Appboy/BrazeiOSPlatform.cs new file mode 100644 index 000000000..e3c95acc9 --- /dev/null +++ b/Assets/Plugins/Appboy/BrazeiOSPlatform.cs @@ -0,0 +1,420 @@ +using Appboy; +using Appboy.Internal; +using Appboy.Models; +using Appboy.Utilities; +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using UnityEngine; + +#if UNITY_IOS + +public class BrazeiOSPlatform : BrazePlatform { + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logCustomEvent(string eventName, string properties); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _changeUser(string userId); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logPurchase(string productId, string currencyCode, string price, int quantity, string properties); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserFirstName(string firstName); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserLastName(string lastName); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserPhoneNumber(string phoneNumber); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserAvatarImageURL(string imageURL); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserGender(int gender); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserEmail(string email); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserDateOfBirth(int year, int month, int day); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserCountry(string country); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserHomeCity(string city); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserEmailNotificationSubscriptionType(int emailNotificationSubscriptionType); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserPushNotificationSubscriptionType(int pushNotificationSubscriptionType); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeBool(string key, bool val); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeInt(string key, int val); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeFloat(string key, float val); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeString(string key, string val); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeToNow(string key); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeToSecondsFromEpoch(string key, long seconds); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _unsetCustomUserAttribute(string key); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _incrementCustomUserAttribute(string key, int incrementValue); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setCustomUserAttributeArray(string key, string[] array, int size); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _addToCustomUserAttributeArray(string key, string value); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _removeFromCustomUserAttributeArray(string key, string value); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserFacebookData(string facebookId, string firstName, string lastName, string email, string bio, string cityName, int gender, int numberOfFriends, string birthday); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setUserTwitterData(int twitterUserId, string twitterHandle, string name, string description, int followerCount, int followingCount, int tweetCount, string profileImageUrl); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logInAppMessageClicked(string inAppMessageJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logInAppMessageImpression(string inAppMessageJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logCardImpression(string cardJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logCardClicked(string cardJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _requestFeedRefresh(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _requestFeedRefreshFromCache(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logFeedDisplayed(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logContentCardImpression(string cardJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logContentCardClicked(string cardJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logContentCardDismissed(string cardJSONString); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _requestContentCardsRefresh(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _requestContentCardsRefreshFromCache(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _logContentCardsDisplayed(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _displayNextInAppMessage(bool withDelegate); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _wipeData(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _enableSDK(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _disableSDK(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _setAttributionData(string network, string campaign, string adgroup, string creative); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _requestGeofences(decimal latitude, decimal longitude); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _requestImmediateDataFlush(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern string _getInstallTrackingId(); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _registerAppboyPushMessages(string registrationTokenBase64); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _promptUserForPushPermissions(bool provisional); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _addAlias(string label, string alias); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _configureListener(int messageType, string gameobject, string method); + + [System.Runtime.InteropServices.DllImport("__Internal")] + private static extern void _configureInternalListener(int messageType); + + public void LogCustomEvent(string eventName) { + _logCustomEvent(eventName, null); + } + + public void LogCustomEvent(string eventName, Dictionary properties) { + var propertiesString = Json.Serialize(properties); + _logCustomEvent(eventName, propertiesString); + } + + public void LogPurchase(string productId, string currencyCode, decimal price, int quantity) { + _logPurchase(productId, currencyCode, price.ToString(), quantity, null); + } + + public void LogPurchase(string productId, string currencyCode, decimal price, int quantity, Dictionary properties) { + var propertiesString = Json.Serialize(properties); + _logPurchase(productId, currencyCode, price.ToString(), quantity, propertiesString); + } + + public void ChangeUser(string userId) { + _changeUser(userId); + } + + public void SetUserFirstName(string firstName) { + _setUserFirstName(firstName); + } + + public void SetUserLastName(string lastName) { + _setUserLastName(lastName); + } + + public void SetUserEmail(string email) { + _setUserEmail(email); + } + + public void SetUserGender(Gender gender) { + _setUserGender((int)gender); + } + + public void SetUserDateOfBirth(int year, int month, int day) { + _setUserDateOfBirth(year, month, day); + } + + public void SetUserCountry(string country) { + _setUserCountry(country); + } + + public void SetUserHomeCity(string city) { + _setUserHomeCity(city); + } + + public void SetUserEmailNotificationSubscriptionType(AppboyNotificationSubscriptionType emailNotificationSubscriptionType) { + _setUserEmailNotificationSubscriptionType((int)emailNotificationSubscriptionType); + } + + public void SetUserPushNotificationSubscriptionType(AppboyNotificationSubscriptionType pushNotificationSubscriptionType) { + _setUserPushNotificationSubscriptionType((int)pushNotificationSubscriptionType); + } + + public void SetUserPhoneNumber(string phoneNumber) { + _setUserPhoneNumber(phoneNumber); + } + + public void SetUserAvatarImageURL(string imageURL) { + _setUserAvatarImageURL(imageURL); + } + + public void SetCustomUserAttribute(string key, bool value) { + _setCustomUserAttributeBool(key, value); + } + + public void SetCustomUserAttribute(string key, int value) { + _setCustomUserAttributeInt(key, value); + } + + public void SetCustomUserAttribute(string key, float value) { + _setCustomUserAttributeFloat(key, value); + } + + public void SetCustomUserAttribute(string key, string value) { + _setCustomUserAttributeString(key, value); + } + + public void SetCustomUserAttributeToNow(string key) { + _setCustomUserAttributeToNow(key); + } + + public void SetCustomUserAttributeToSecondsFromEpoch(string key, long secondsFromEpoch) { + _setCustomUserAttributeToSecondsFromEpoch(key, secondsFromEpoch); + } + + public void UnsetCustomUserAttribute(string key) { + _unsetCustomUserAttribute(key); + } + + public void IncrementCustomUserAttribute(string key, int incrementValue) { + _incrementCustomUserAttribute(key, incrementValue); + } + + public void SetCustomUserAttributeArray(string key, List array, int size) { + if (array == null) { + _setCustomUserAttributeArray(key, null, size); + } else { + _setCustomUserAttributeArray(key, array.ToArray(), size); + } + } + + public void AddToCustomUserAttributeArray(string key, string value) { + _addToCustomUserAttributeArray(key, value); + } + + public void RemoveFromCustomUserAttributeArray(string key, string value) { + _removeFromCustomUserAttributeArray(key, value); + } + + public void setUserFacebookData(string facebookId, string firstName, string lastName, string email, string bio, string cityName, Gender? gender, int? numberOfFriends, string birthday) { + _setUserFacebookData(facebookId, firstName, lastName, email, bio, cityName, gender == null ? -1 : (int)gender, numberOfFriends == null ? -1 : (int)numberOfFriends, birthday); + } + + public void setUserTwitterData(int? twitterUserId, string twitterHandle, string name, string description, int? followerCount, int? followingCount, int? tweetCount, string profileImageUrl) { + _setUserTwitterData(twitterUserId == null ? -1 : (int)twitterUserId, twitterHandle, name, description, followerCount == null ? -1 : (int)followerCount, followingCount == null ? -1 : (int)followingCount, tweetCount == null ? -1 : (int)tweetCount, profileImageUrl); + } + + public void DisplayNextInAppMessage(bool withDelegate) { + _displayNextInAppMessage(withDelegate); + } + + public void LogInAppMessageClicked(string inAppMessageJSONString) { + _logInAppMessageClicked(inAppMessageJSONString); + } + + public void LogInAppMessageImpression(string inAppMessageJSONString) { + _logInAppMessageImpression(inAppMessageJSONString); + } + + public void LogInAppMessageButtonClicked(string inAppMessageJSONString, int buttonID) { + _logInAppMessageButtonClicked(inAppMessageJSONString, buttonID); + } + + public void LogCardImpression(string cardJSONString) { + _logCardImpression(cardJSONString); + } + + public void LogCardClicked(string cardJSONString) { + _logCardClicked(cardJSONString); + } + + public void RequestFeedRefresh() { + _requestFeedRefresh(); + } + + public void RequestFeedRefreshFromCache() { + _requestFeedRefreshFromCache(); + } + + public void LogFeedDisplayed() { + _logFeedDisplayed(); + } + + public void LogContentCardImpression(string cardJSONString) { + _logContentCardImpression(cardJSONString); + } + + public void LogContentCardClicked(string cardJSONString) { + _logContentCardClicked(cardJSONString); + } + + public void LogContentCardDismissed(string cardJSONString) { + _logContentCardDismissed(cardJSONString); + } + + public void RequestContentCardsRefresh() { + _requestContentCardsRefresh(); + } + + public void RequestContentCardsRefreshFromCache() { + _requestContentCardsRefreshFromCache(); + } + + public void LogContentCardsDisplayed() { + _logContentCardsDisplayed(); + } + + public void WipeData() { + _wipeData(); + } + + public void EnableSDK() { + _enableSDK(); + } + + public void DisableSDK() { + _disableSDK(); + } + + public string GetInstallTrackingId() { + return _getInstallTrackingId(); + } + + public void SetAttributionData(string network, string campaign, string adgroup, string creative) { + _setAttributionData(network, campaign, adgroup, creative); + } + + public void RequestLocationInitialization() { + // no-op + } + + public void RegisterAppboyPushMessages(byte[] registrationDeviceToken) { + string registrationTokenBase64 = Convert.ToBase64String(registrationDeviceToken); + _registerAppboyPushMessages(registrationTokenBase64); + } + + public void PromptUserForPushPermissions(bool provisional, PushPromptResponseReceived reponseDelegate = null) { + if (reponseDelegate != null) { + _configureInternalListener((int)BrazeUnityMessageType.PUSH_PERMISSIONS_PROMPT_RESPONSE); + BrazeInternalGameObject.setPushPromptResponseReceivedDelegate(reponseDelegate); + } + _promptUserForPushPermissions(provisional); + } + + public void SetPushTokenReceivedFromSystemDelegate(PushTokenReceivedFromSystem tokenDelegate) { + if (tokenDelegate == null) { + return; + } + BrazeInternalGameObject.setPushTokenReceivedFromSystemDelegate(tokenDelegate); + _configureInternalListener((int)BrazeUnityMessageType.PUSH_TOKEN_RECEIVED_FROM_SYSTEM); + } + + public void RequestGeofences(decimal latitude, decimal longitude) { + _requestGeofences(latitude, longitude); + } + + public void RequestImmediateDataFlush() { + _requestImmediateDataFlush(); + } + + public void AddAlias(string alias, string label) { + _addAlias(alias, label); + } + + public void ConfigureListener(BrazeUnityMessageType messageType, string gameobject, string method) { + _configureListener((int)messageType, gameobject, method); + } +} + +#endif diff --git a/Assets/Plugins/Appboy/BrazeiOSPlatform.cs.meta b/Assets/Plugins/Appboy/BrazeiOSPlatform.cs.meta new file mode 100644 index 000000000..8ca5d9373 --- /dev/null +++ b/Assets/Plugins/Appboy/BrazeiOSPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5f08496014c394002aa024d327451592 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/Appboy/Editor/AppboyConfig.cs b/Assets/Plugins/Appboy/Editor/AppboyConfig.cs index 043d035c9..0c269fedd 100644 --- a/Assets/Plugins/Appboy/Editor/AppboyConfig.cs +++ b/Assets/Plugins/Appboy/Editor/AppboyConfig.cs @@ -98,6 +98,8 @@ public class AppboyConfig : ScriptableObject { private string androidPushSmallNotificationIcon = string.Empty; [SerializeField] private string androidPushLargeNotificationIcon = string.Empty; + [SerializeField] + private bool androidDelaySendingPushIntents = false; // In-App Messages // iOS @@ -365,6 +367,11 @@ public static string AndroidPushLargeNotificationIcon { set { SetProperty(ref Instance.androidPushLargeNotificationIcon, value); } } + public static bool AndroidPushNotificationDelayedSendingEnabled { + get { return Instance.androidDelaySendingPushIntents; } + set { SetProperty(ref Instance.androidDelaySendingPushIntents, value); } + } + // In-App Messages public static string AndroidInAppMessageListenerGameObjectName { get { return Instance.androidInAppMessageListenerGameObjectName; } diff --git a/Assets/Plugins/Appboy/Editor/AppboyConfigEditor.cs b/Assets/Plugins/Appboy/Editor/AppboyConfigEditor.cs index a09bbeba0..74524d5cd 100644 --- a/Assets/Plugins/Appboy/Editor/AppboyConfigEditor.cs +++ b/Assets/Plugins/Appboy/Editor/AppboyConfigEditor.cs @@ -319,6 +319,9 @@ private void AndroidBuildGUIPush() { AppboyConfig.AndroidPushDefaultNotificationAccentColor = EditorGUILayout.TextField(" Default Notification Accent Color", AppboyConfig.AndroidPushDefaultNotificationAccentColor); EditorGUILayout.LabelField(" Enter a valid hex value, e.g. \"0xFF00FF00\"", EditorStyles.wordWrappedMiniLabel); + AppboyConfig.AndroidPushNotificationDelayedSendingEnabled = EditorGUILayout.ToggleLeft(" Delay Sending Push Notification Intents", AppboyConfig.AndroidPushNotificationDelayedSendingEnabled); + EditorGUILayout.LabelField(" Delay sending push notification data until the Unity native libraries have finished loading", EditorStyles.wordWrappedMiniLabel); + EditorGUI.indentLevel--; } diff --git a/Assets/Plugins/Appboy/Editor/PreBuild.cs b/Assets/Plugins/Appboy/Editor/PreBuild.cs index 20ca2a43e..11204e1b0 100644 --- a/Assets/Plugins/Appboy/Editor/PreBuild.cs +++ b/Assets/Plugins/Appboy/Editor/PreBuild.cs @@ -59,6 +59,7 @@ private static string GenerateConfigFile() { cfg = AddStringKey(cfg, "com_appboy_default_notification_channel_description", AppboyConfig.AndroidPushDefaultNotificationChannelDescription); cfg = AddDrawableKey(cfg, "com_appboy_push_small_notification_icon", AppboyConfig.AndroidPushSmallNotificationIcon); cfg = AddDrawableKey(cfg, "com_appboy_push_large_notification_icon", AppboyConfig.AndroidPushLargeNotificationIcon); + cfg = AddBooleanKey(cfg, "com_braze_delay_sending_push_intents", AppboyConfig.AndroidPushNotificationDelayedSendingEnabled); // In App Messages cfg = AddStringKey(cfg, "com_appboy_inapp_listener_game_object_name", AppboyConfig.AndroidInAppMessageListenerGameObjectName); @@ -142,4 +143,4 @@ private static string AddHexColorIntegerKey(string buffer, string key, string va } } } -#endif \ No newline at end of file +#endif diff --git a/Assets/Plugins/Appboy/models/Cards/Card.cs b/Assets/Plugins/Appboy/models/Cards/Card.cs index 7ed4a0c58..b884c406a 100755 --- a/Assets/Plugins/Appboy/models/Cards/Card.cs +++ b/Assets/Plugins/Appboy/models/Cards/Card.cs @@ -68,7 +68,7 @@ public override string ToString() { public void LogImpression() { if (!string.IsNullOrEmpty(ID)) { #if UNITY_ANDROID - AppboyBinding.Appboy.Call("logFeedCardImpression", ID); + AppboyBinding.LogCardImpression(ID); #elif UNITY_IOS AppboyBinding.LogCardImpression(JsonString); #endif @@ -86,7 +86,7 @@ public string CategoriesToString() { public void LogClick() { if (!string.IsNullOrEmpty(ID)) { #if UNITY_ANDROID - AppboyBinding.Appboy.Call("logFeedCardClick", ID); + AppboyBinding.LogCardClicked(ID); #elif UNITY_IOS AppboyBinding.LogCardClicked(JsonString); #endif diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a0f6a11..2bcb6be3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## 3.3.0 + +##### Breaking +- Updated the Android plugin to use Braze Android SDK 14.0.0. + +##### Added +- Added the ability to delay sending Android push notification data to the Unity layer until the native libraries have finished loading and any AppboyBinding method has been called. + - Configured under "Braze Configuration -> Automate Unity Android Integration -> Push Configuration -> Delay Sending Push Notification Intents". + - Pending Android push notification intents are flushed automatically after the first call to any method on the Android binding is made. + - To optionally have finer control over when these push notification intents are flushed, call the following from Unity: + ``` + #if UNITY_ANDROID + BrazeAndroidPlatform binding = (BrazeAndroidPlatform) Appboy.AppboyBinding.mBinding; + binding.FlushAndroidPendingPushIntents(); + #endif + ``` + ## 3.2.0 ##### Breaking diff --git a/LICENSE b/LICENSE index 6d2c4c4c5..e79585e4d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2018 Braze, Inc. +Copyright (c) 2021 Braze, Inc. All rights reserved. * Use of source code or binaries contained within Braze’s SDKs is permitted only to enable use of the Braze platform by customers of Braze. diff --git a/braze-logo.png b/braze-logo.png index 5fd2ed245..c18288597 100644 Binary files a/braze-logo.png and b/braze-logo.png differ diff --git a/scripts/Gemfile b/scripts/Gemfile deleted file mode 100644 index 336e7e5ed..000000000 --- a/scripts/Gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source 'http://rubygems.org' - -# gem 'nokogiri' -gem 'fastlane' -gem 'appboy_sdk_release_utils', :git => 'git@github.com:Appboy/sdk-utils.git' \ No newline at end of file diff --git a/scripts/Gemfile.lock b/scripts/Gemfile.lock deleted file mode 100644 index 498572296..000000000 --- a/scripts/Gemfile.lock +++ /dev/null @@ -1,154 +0,0 @@ -GIT - remote: git@github.com:Appboy/sdk-utils.git - revision: 34e79632434dde35ee296cb5bcaaefef14732663 - specs: - appboy_sdk_release_utils (0.0.1) - -GEM - remote: http://rubygems.org/ - specs: - CFPropertyList (2.3.4) - activesupport (4.2.7.1) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - addressable (2.5.0) - public_suffix (~> 2.0, >= 2.0.2) - babosa (1.0.2) - claide (1.0.1) - colored (1.2) - commander (4.4.3) - highline (~> 1.7.2) - domain_name (0.5.20161129) - unf (>= 0.0.5, < 1.0.0) - dotenv (2.1.2) - excon (0.54.0) - faraday (0.11.0) - multipart-post (>= 1.2, < 3) - faraday-cookie_jar (0.0.6) - faraday (>= 0.7.4) - http-cookie (~> 1.0.0) - faraday_middleware (0.11.0.1) - faraday (>= 0.7.4, < 1.0) - fastimage (2.0.1) - addressable (~> 2) - fastlane (2.10.0) - activesupport (< 5) - addressable (>= 2.3, < 3.0.0) - babosa (>= 1.0.2, < 2.0.0) - bundler (~> 1.12) - colored - commander (>= 4.4.0, < 5.0.0) - dotenv (>= 2.1.1, < 3.0.0) - excon (>= 0.45.0, < 1.0.0) - faraday (~> 0.9) - faraday-cookie_jar (~> 0.0.6) - faraday_middleware (~> 0.9) - fastimage (>= 1.6) - gh_inspector (>= 1.0.1, < 2.0.0) - google-api-client (~> 0.9.2) - highline (>= 1.7.2, < 2.0.0) - json (< 3.0.0) - mini_magick (~> 4.5.1) - multi_json - multi_xml (~> 0.5) - multipart-post (~> 2.0.0) - plist (>= 3.1.0, < 4.0.0) - rubyzip (>= 1.1.0, < 2.0.0) - security (= 0.1.3) - slack-notifier (>= 1.3, < 2.0.0) - terminal-notifier (>= 1.6.2, < 2.0.0) - terminal-table (>= 1.4.5, < 2.0.0) - word_wrap (~> 1.0.0) - xcodeproj (>= 0.20, < 2.0.0) - xcpretty (>= 0.2.4, < 1.0.0) - xcpretty-travis-formatter (>= 0.0.3) - gh_inspector (1.0.3) - google-api-client (0.9.23) - addressable (~> 2.3) - googleauth (~> 0.5) - httpclient (~> 2.7) - hurley (~> 0.1) - memoist (~> 0.11) - mime-types (>= 1.6) - representable (~> 2.3.0) - retriable (~> 2.0) - googleauth (0.5.1) - faraday (~> 0.9) - jwt (~> 1.4) - logging (~> 2.0) - memoist (~> 0.12) - multi_json (~> 1.11) - os (~> 0.9) - signet (~> 0.7) - highline (1.7.8) - http-cookie (1.0.3) - domain_name (~> 0.5) - httpclient (2.8.3) - hurley (0.2) - i18n (0.7.0) - json (1.8.6) - jwt (1.5.6) - little-plugger (1.1.4) - logging (2.1.0) - little-plugger (~> 1.1) - multi_json (~> 1.10) - memoist (0.15.0) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_magick (4.5.1) - minitest (5.10.1) - multi_json (1.12.1) - multi_xml (0.6.0) - multipart-post (2.0.0) - nanaimo (0.2.3) - os (0.9.6) - plist (3.2.0) - public_suffix (2.0.5) - representable (2.3.0) - uber (~> 0.0.7) - retriable (2.1.0) - rouge (1.11.1) - rubyzip (1.2.0) - security (0.1.3) - signet (0.7.3) - addressable (~> 2.3) - faraday (~> 0.9) - jwt (~> 1.5) - multi_json (~> 1.10) - slack-notifier (1.5.1) - terminal-notifier (1.7.1) - terminal-table (1.7.3) - unicode-display_width (~> 1.1.1) - thread_safe (0.3.5) - tzinfo (1.2.2) - thread_safe (~> 0.1) - uber (0.0.15) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.2) - unicode-display_width (1.1.3) - word_wrap (1.0.0) - xcodeproj (1.4.2) - CFPropertyList (~> 2.3.3) - activesupport (>= 3) - claide (>= 1.0.1, < 2.0) - colored (~> 1.2) - nanaimo (~> 0.2.3) - xcpretty (0.2.4) - rouge (~> 1.8) - xcpretty-travis-formatter (0.0.4) - xcpretty (~> 0.2, >= 0.0.7) - -PLATFORMS - ruby - -DEPENDENCIES - appboy_sdk_release_utils! - fastlane - -BUNDLED WITH - 1.17.2 diff --git a/scripts/generate_package.sh b/scripts/generate_package.sh deleted file mode 100755 index 87dfb46ba..000000000 --- a/scripts/generate_package.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -PROJECT_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd ) - -# https://unix.stackexchange.com/questions/196690/best-and-short-way-to-run-a-program-if-another-is-not-installed -function unity_app_cmd { - # Ask MacOS for the path of the currently running Unity process - RUNNING_UNITY_APP="$(osascript -e 'tell application "System Events" to POSIX path of (file of process "Unity" as alias)')/Contents/MacOS/Unity" - UNITY_STANDALONE="/Applications/Unity/Unity.app/Contents/MacOS/Unity" - - if [ -f $RUNNING_UNITY_APP ] - then - echo "Using Unity $RUNNING_UNITY_APP" - $RUNNING_UNITY_APP "$@" - - else - echo "Using Unity $UNITY_STANDALONE" - $UNITY_STANDALONE "$@" - fi -} - -rm -rf ../unity-package -mkdir ../unity-package - -unity_app_cmd -batchmode -nographics -projectPath $PROJECT_ROOT -executeMethod Appboy.Editor.Build.ExportAllPackages -quit \ - && echo "Unity Packages exported to $PROJECT_ROOT/unity-package/" || echo "Failed to export package. Please have your Unity instance running next time!" diff --git a/scripts/get_my_unity_version.sh b/scripts/get_my_unity_version.sh deleted file mode 100755 index 04d177219..000000000 --- a/scripts/get_my_unity_version.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -RUNNING_UNITY_APP="$(osascript -e 'tell application "System Events" to POSIX path of (file of process "Unity" as alias)')" -echo $RUNNING_UNITY_APP \ No newline at end of file diff --git a/scripts/manual_move_aars_from_m2.sh b/scripts/manual_move_aars_from_m2.sh deleted file mode 100755 index fe1e9619d..000000000 --- a/scripts/manual_move_aars_from_m2.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -VERSION=$1 - -cp ~/.m2/repository/com/appboy/android-sdk-base/$VERSION/android-sdk-base-$VERSION.aar ../Assets/Plugins/Android/appboy.aar -cp ~/.m2/repository/com/appboy/android-sdk-ui/$VERSION/android-sdk-ui-$VERSION.aar ../Assets/Plugins/Android/appboy-ui.aar -cp ~/.m2/repository/com/appboy/android-sdk-unity/$VERSION/android-sdk-unity-$VERSION.aar ../Assets/Plugins/Android/appboy-unity.aar diff --git a/scripts/release.rb b/scripts/release.rb deleted file mode 100755 index fdcbdbbba..000000000 --- a/scripts/release.rb +++ /dev/null @@ -1,142 +0,0 @@ -require 'pathname' -require 'tempfile' -require 'nokogiri' - -ROOT_DIRECTORY = Pathname.getwd().to_s() -SCRIPTS_DIRECTORY = File.join(ROOT_DIRECTORY, "scripts") -puts SCRIPTS_DIRECTORY - -TMP_STAGING_DIRECTORY = File.join(Dir.tmpdir, "appboy-unity-sdk") - -def check_and_remove_directory(directory) - if File.exists?(directory) - `rm -rf #{directory}` - end -end - -def get_release_directory - return "#{ROOT_DIRECTORY}/Public" -end - -def get_version_number - changelog_filepath = File.join(ROOT_DIRECTORY, "Public/CHANGELOG.md") - puts("Getting the version number from CHANGELOG.md") - version_number = (File.readlines(changelog_filepath))[0] - version_number.tr!('## ', '') - version_number.strip!() - return version_number -end - -def pretty_puts(msg) - puts(" ") - puts("=======") - puts(msg) - puts("=======") - puts(" ") -end - -# Assert our files and directories are where we expect it -unless (File.exists?(SCRIPTS_DIRECTORY) && File.exists?(get_release_directory())) - puts "Expected #{SCRIPTS_DIRECTORY} and #{get_release_directory()} to exist. Exiting." - exit() -end - -pretty_puts("Release directory #{get_release_directory()}") - -stage_repo = false -push_to_public_repo = false -show_help = false -argument_array = Array.new(ARGV) - -ARGV.each do |a| - argument_array.shift - case a - when '--stage-repo' - stage_repo = true - when '--push-dangerous' - push_to_public_repo = true - when '--help' - show_help = true - end -end - -if ARGV.empty? - show_help = true -end - -# Display help and exit if necessary -if show_help - puts("Appboy Unity SDK release script. This SDK copies the Plugins and the sample app to the release directory.") - puts("Run this file from the git clone root of unity-sdk.") - puts("") - puts("Usage: ./release.rb [options]") - puts("Options:") - puts("\t--help\tThe message you're seeing now.") - puts("\t--stage-repo\tPush the SDK and sample app project changes to a local appboy-unity-sdk repo for staging.") - puts("\t--push-dangerous\tActually push the SDK changes in the staged repo to the public repo - you probably should do this manually.") - exit(0) -end - -pretty_puts("Clean up the Public folder before copying files in") -check_and_remove_directory("Public/unity-samples") -check_and_remove_directory("Public/Libraries") -check_and_remove_directory("Public/Plugins") -check_and_remove_directory("Public/Assets") -check_and_remove_directory("Public/scripts") -check_and_remove_directory("unity-samples/build") - -pretty_puts("Copying sample app, scripts and Assets folder into Public") -puts `cp -vR "Assets" "Public"` -puts `cp -vR "unity-samples" "Public"` -puts `cp -vR "scripts" "Public"` -puts `cp -v ".gitignore" "Public"` - -if stage_repo - pretty_puts("Cloning the public repo and adding changes.") - pretty_puts("the appboy-unity-sdk path is #{TMP_STAGING_DIRECTORY}") - if File.exists?(TMP_STAGING_DIRECTORY) - FileUtils.rm_rf(TMP_STAGING_DIRECTORY) - end - puts `git clone git@github.com:Appboy/appboy-unity-sdk.git #{TMP_STAGING_DIRECTORY}` - Dir.chdir(TMP_STAGING_DIRECTORY) - pretty_puts("Removing old directories.") - puts `git rm -rf #{TMP_STAGING_DIRECTORY}/*` - pretty_puts("Copying directories from Public. #{get_release_directory()} to #{TMP_STAGING_DIRECTORY}") - puts `cp -vR #{get_release_directory()}/ #{TMP_STAGING_DIRECTORY}` - puts `git add .` - puts `git add -u .` - - puts `open #{TMP_STAGING_DIRECTORY}` - puts("Please check the diff on the public repo at #{TMP_STAGING_DIRECTORY}. \t Please type \"continue\" when you finish to commit your changes.") - STDOUT.flush - arguments = STDIN.gets.chomp - if arguments != 'continue' - exit(0) - end - pretty_puts("Adding to git and committing") - puts `git commit -am "Updating Unity plugins for version #{get_version_number()}"` - puts `git tag -a "#{get_version_number()}" -m "SDK version #{get_version_number()}"` - - if push_to_public_repo - pretty_puts("Publishing changes to the public github repo.") - puts `git push origin master` - - # Push the release tags - puts `git push --tags` - else - puts("Not pushing changes to the public repo. To do so manually, run \"git push origin master;git push --tags\" and tag the release.") - end - - # Return back to the original working directory - Dir.chdir(ROOT_DIRECTORY) -end - -pretty_puts("Generating Unity packages") - -Dir.chdir(SCRIPTS_DIRECTORY) do - puts `./generate_package.sh` -end -puts("Remember to upload the packages to the public release using the github UI.") - -pretty_puts("Release complete! Staging directory: #{TMP_STAGING_DIRECTORY}.") -puts("If manually releasing, run -> \"cd #{TMP_STAGING_DIRECTORY};git push origin master;git push --tags\"") diff --git a/scripts/update_android.rb b/scripts/update_android.rb deleted file mode 100644 index 52e2bc473..000000000 --- a/scripts/update_android.rb +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env ruby - -require 'appboy_sdk_release_utils' -require 'pathname' - -class ArtifactModulePair - attr_accessor :modulePath, :moduleName - - def initialize(m, n) - @modulePath, @moduleName = m, n - end -end - -ROOT_DIRECTORY = File.expand_path(File.join(Pathname.getwd().to_s(), "..")) -puts "ROOT_DIRECTORY #{ROOT_DIRECTORY}" - -ANDROID_MODULES = [ - ArtifactModulePair.new("android-sdk-base", "appboy"), - ArtifactModulePair.new("android-sdk-ui", "appboy-ui"), - ArtifactModulePair.new("android-sdk-unity", "appboy-unity"), -] - -BUILD_DIR = File.join(ROOT_DIRECTORY, "scripts/build") - -# AARs for the unitypackage -ANDROID_PLUGINS_DIRECTORY = File.join(ROOT_DIRECTORY, "Assets/Plugins/Android") - -# Public artifact links -ANDROID_CHANGELOG_URL = "https://raw.githubusercontent.com/Appboy/appboy-android-sdk/master/CHANGELOG.md" -ARTIFACT_BASE_URL = "https://github.com/Appboy/appboy-android-sdk/blob/gh-pages/sdk/com/appboy" - -# Assert our files and directories are where we expect it -unless (File.exists?(ANDROID_PLUGINS_DIRECTORY)) - puts "Expected #{ANDROID_PLUGINS_DIRECTORY} to exist. Exiting." - exit() -end - -unless Dir.exist?(BUILD_DIR) - FileUtils.mkdir(BUILD_DIR) -end - -# Get a file and return its path -def get_remote_file(url, dest_filename) - output_file = File.join(BUILD_DIR, dest_filename) - Dir.chdir(BUILD_DIR) do - puts "Downloading #{url} to #{output_file} ..." - puts `wget #{url} -O #{output_file}` - end - return output_file -end - -def get_aar_file(module_name, output_filename, latest_sdk) - # The URL paths look like: - # https://github.com/Appboy/appboy-android-sdk/blob/gh-pages/sdk/com/appboy/android-sdk-base/8.0.1/android-sdk-base-8.0.1.aar?raw=true - return get_remote_file("#{ARTIFACT_BASE_URL}/#{module_name}/#{latest_sdk}/#{module_name}-#{latest_sdk}.aar?raw=true", "#{output_filename}.aar") -end - -# Simple pretty-printing that breaks up the quite large amount of text this script outputs -def puts_nicely(prefix_msg) - puts " " - puts "===========" - puts prefix_msg.upcase - puts "===========" - puts " " -end - -# Download the changelog and get the latest version number -def get_latest_android_sdk_version() - changelogPath = get_remote_file(ANDROID_CHANGELOG_URL, "android_public_changelog.md") - release_utils = AppboySDKReleaseUtils.new() - return release_utils.get_version_number(changelogPath) -end - -def replace_file(directory, file) - # Overwrite the existing file - FileUtils.cp(file, directory) -end - -puts_nicely("Getting latest SDK version") -latest_sdk = get_latest_android_sdk_version() -puts "Latest Android SDK version #{latest_sdk}" - -puts_nicely("Downloading artifacts") - -# Loop over the modules and download each -ANDROID_MODULES.each { |module_pair| - puts_nicely("Downloading and swapping artifact :#{module_pair.modulePath}") - artifact = get_aar_file(module_pair.modulePath, module_pair.moduleName, latest_sdk) - - replace_file(ANDROID_PLUGINS_DIRECTORY, artifact) -} - -puts_nicely("All done. Don't forget 'git add -A' to add the new artifacts!") diff --git a/scripts/update_ios.rb b/scripts/update_ios.rb deleted file mode 100644 index 968720702..000000000 --- a/scripts/update_ios.rb +++ /dev/null @@ -1,135 +0,0 @@ -require 'fileutils' - -class AppboyUnityReleaseHelper - attr_accessor :ios_assets_plugin_directory - attr_accessor :build_directory - attr_accessor :appboy_ios_sdk_framework_name - attr_accessor :sd_webimage_artifact_name - attr_accessor :framework_unzip_directory - attr_accessor :framework_lipo_removal_directory - - def initialize - # Assumes this script is being ran from `./scripts/` - # This gets the absolute path of the parent directory - @unity_sdk_root_directory = File.expand_path("..", Dir.pwd) - - @build_directory = File.join(@unity_sdk_root_directory, "scripts/build") - @ios_assets_plugin_directory = File.join(@unity_sdk_root_directory, "Assets/Plugins/iOS") - - # The framework name (pre .zip) as it appears on https://github.com/Appboy/appboy-ios-sdk/releases - @appboy_ios_sdk_artifact_name = "Appboy_iOS_SDK" - @sd_webimage_artifact_name = "SDWebImage" - - @appboy_ios_sdk_repo_slash_name = "Appboy/appboy-ios-sdk" - @framework_unzip_directory = File.join(@build_directory, "unzipped_framework_files") - @framework_lipo_removal_directory = File.join(@build_directory, "lipo_removed_frameworks") - - # Check if the current directory this scriptis running from is valid - if !File.exist?(ios_assets_plugin_directory) - abort("This script expects the ios assets plugin folder to be found at #{ios_assets_plugin_directory}") - end - - create_build_directories() - end - - def pretty_puts(msg) - puts(" ") - puts("=======") - puts(msg) - puts("=======") - puts(" ") - end - - def create_build_directories() - pretty_puts("deleting and recreating build directories") - puts `rm -rf #{@build_directory}` - FileUtils.mkdir_p(@build_directory) - FileUtils.mkdir_p(@framework_unzip_directory) - FileUtils.mkdir_p(@framework_lipo_removal_directory) - end - - # Downloads the latest release artifact (like Appboy_iOS_SDK.framework) under the repo/name (i.e. Appboy/appboy-ios-sdk) - # Then unzips the release artifact - # Lastly returns the directory of the unzipped files - # Generifies a command such as "curl -s https://api.github.com/repos/Appboy/appboy-ios-sdk/releases/latest | grep "browser_download_url.*Appboy_iOS_SDK.*zip" | cut -d '"' -f 4 | wget -O Appboy_iOS_SDK.framework.zip" - def retrieve_latest_release_with_name(repo_name_slash_project, release_artifact_name) - framework_zip_filename = "#{release_artifact_name}.framework.zip" - - puts "framework_zip_filename #{framework_zip_filename}" - - # Extracting the wget commands for readability - curl_cmd = "curl -s https://api.github.com/repos/#{repo_name_slash_project}/releases/latest" - grep_cmd = "grep \"browser_download_url.*#{framework_zip_filename}\"" - # Removes the quotes from the filename - cut_cmd = "cut -d '\"' -f 4" - wget_cmd = "wget -i - -O #{framework_zip_filename}" - - Dir.chdir(@build_directory) do - # Delete our old framework zip - puts "deleting framework zip at path #{framework_zip_filename}" - puts `rm -rf #{framework_zip_filename}` - - full_cmd = "#{curl_cmd}|#{grep_cmd}|#{cut_cmd}|#{wget_cmd}" - # Download a new framework zip - puts "running #{full_cmd}" - puts(`#{full_cmd}`) - - # Delete any existing framework zip files and unzip anew - puts `rm -rf #{@framework_unzip_directory}` - puts `mkdir #{@framework_unzip_directory}` - puts `unzip #{framework_zip_filename} -d #{@framework_unzip_directory}` - end - - return File.join(@framework_unzip_directory, "iOS") - end - - # framework_name like Appboy_iOS_SDK - # return the output framework path - def remove_simulator_architecture(framework_name, framework_source_directory, output_directory) - puts "Removing simulator architecture for #{framework_name} in source dir #{framework_source_directory} and outputting to #{output_directory}" - # Like Appboy_iOS_SDK.framework but in another directory - output_framework_folder = File.join(output_directory, "#{framework_name}.framework") - - # Copy the framework to the output directory - puts `cp -r #{framework_source_directory}/#{framework_name}.framework/ #{output_framework_folder}/` - - # Lipo the simulator architectures and overwrite the executables in place - puts `lipo -remove x86_64 #{output_framework_folder}/#{framework_name} -o #{output_framework_folder}/#{framework_name}` - puts `lipo -remove i386 #{output_framework_folder}/#{framework_name} -o #{output_framework_folder}/#{framework_name}` - - # Print the lipo info on the frameworks after. If lipo failed, fail the entire script - arch_list = `lipo -info #{output_framework_folder}/#{framework_name}` - puts "contained architectures #{arch_list}" - if (arch_list.include?("x86_64") || arch_list.include?("i386") || !arch_list.include?("armv7") || !arch_list.include?("arm64")) - abort("Invalid architectures!") - end - - return "#{output_framework_folder}/#{framework_name}" - end - - def overwrite_framework(framework_name, framework_source_directory, framework_output_directory) - puts "Overwriting framework #{framework_name} from source dir #{framework_source_directory} to output dir #{framework_output_directory}" - puts `rm -rf #{framework_output_directory}/#{framework_name}.framework` - puts `cp -r #{framework_source_directory}/#{framework_name}.framework/ #{framework_output_directory}/#{framework_name}.framework/` - end - - def performUpdate() - # Retrieve the files - pretty_puts("retrieving the frameworks from the kit public release") - framework_unzipped_directory = retrieve_latest_release_with_name(@appboy_ios_sdk_repo_slash_name, @appboy_ios_sdk_artifact_name) - puts "framework_unzipped_directory unzipped from #{framework_unzipped_directory}" - - # Run lipo on the files - pretty_puts("Running lipo on the downloaded frameworks") - remove_simulator_architecture(@appboy_ios_sdk_artifact_name, framework_unzipped_directory, @framework_lipo_removal_directory) - remove_simulator_architecture(@sd_webimage_artifact_name, framework_unzipped_directory, @framework_lipo_removal_directory) - - # Move the files over to the ios_assets_plugin_directory folder - pretty_puts("Moving the lipo'd frameworks to the #{ios_assets_plugin_directory} folder") - overwrite_framework(@appboy_ios_sdk_artifact_name, @framework_lipo_removal_directory, @ios_assets_plugin_directory) - overwrite_framework(@sd_webimage_artifact_name, @framework_lipo_removal_directory, @ios_assets_plugin_directory) - end -end - -release_helper = AppboyUnityReleaseHelper.new() -framework_unzipped_directory = release_helper.performUpdate()