using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using UnityEngine; using TapjoyUnity.Internal.SimpleJSON; #if UNITY_IOS namespace TapjoyUnity.Internal { public sealed class ApiBindingIos : ApiBinding { public static void Install() { ApiBinding.SetInstance(new ApiBindingIos()); } ApiBindingIos() : base("iOS") { Tapjoy_SetUnityVersion(VERSION_NAME); } // Connect public override void Connect(string sdkKey, Dictionary flags) { if (sdkKey == null) { return; } if (flags != null) { foreach (KeyValuePair kvp in flags) { // Is the value a dictionary itself if (kvp.Value.GetType().IsGenericType) { Dictionary dictionaryToTransfer = (Dictionary) kvp.Value; string dictionaryName = kvp.Key; // Communicate with objetive-c to build the dictionary transferDictionaryToObjectiveCWithName(dictionaryToTransfer, dictionaryName); // Tell Objective-C to add the dictionary *dictionaryName* to dictionary "connectFlags" under the key *kvp.key* Tapjoy_SetKeyToDictionaryRefValueInDictionary(kvp.Key, dictionaryName, CONNECT_FLAG_DICTIONARY_NAME); } else { if (kvp.Value == null) { Tapjoy_SetKeyToValueInDictionary(kvp.Key, "", CONNECT_FLAG_DICTIONARY_NAME); } else { var type = kvp.Value.GetType(); if (type.IsEnum) { Tapjoy_SetKeyToIntInDictionary(kvp.Key, Convert.ToInt32(kvp.Value), CONNECT_FLAG_DICTIONARY_NAME); } else if (kvp.Value is int) { Tapjoy_SetKeyToIntInDictionary(kvp.Key, (int)kvp.Value, CONNECT_FLAG_DICTIONARY_NAME); } else if (kvp.Value is bool) { Tapjoy_SetKeyToIntInDictionary(kvp.Key, Convert.ToInt32((bool)kvp.Value), CONNECT_FLAG_DICTIONARY_NAME); } else { Tapjoy_SetKeyToValueInDictionary(kvp.Key, kvp.Value.ToString(), CONNECT_FLAG_DICTIONARY_NAME); } } } } } Tapjoy_Connect(sdkKey); } private void transferDictionaryToObjectiveCWithName(Dictionary dictionary, string dictionaryName) { foreach (KeyValuePair kvp in dictionary) { if (kvp.Value == null) { Tapjoy_SetKeyToValueInDictionary(kvp.Key, "", dictionaryName); continue; } var type = kvp.Value.GetType(); if (type.IsEnum) { Tapjoy_SetKeyToIntInDictionary(kvp.Key, Convert.ToInt32(kvp.Value), dictionaryName); } else if (kvp.Value is int) { Tapjoy_SetKeyToIntInDictionary(kvp.Key, (int)kvp.Value, dictionaryName); } else if (kvp.Value is bool) { Tapjoy_SetKeyToIntInDictionary(kvp.Key, Convert.ToInt32((bool)kvp.Value), dictionaryName); } else { Tapjoy_SetKeyToValueInDictionary(kvp.Key, kvp.Value.ToString(), dictionaryName); } } } // Config public override string GetSDKVersion() { return Tapjoy_GetSDKVersion(); } public override void SetLoggingLevel(LoggingLevel loggingLevel) { Tapjoy_SetLoggingLevel((int)loggingLevel); } public override LoggingLevel GetLoggingLevel() { return (LoggingLevel)Tapjoy_GetLoggingLevel(); } public override void GetPrivacyPolicy() { Tapjoy_GetPrivacyPolicy(); } public override void SetSubjectToGDPR(TJStatus gdprApplicable) { Tapjoy_SetSubjectToGDPRStatus((int)gdprApplicable); } public override int GetSubjectToGDPR() { return Tapjoy_GetSubjectToGDPRStatus (); } public override void SetUserConsent(TJStatus consent) { Tapjoy_SetUserConsentStatus((int)consent); } public override int GetUserConsent () { return Tapjoy_GetUserConsentStatus(); } public override void SetBelowConsentAge(TJStatus belowConsentAge) { Tapjoy_SetBelowConsentAgeStatus((int)belowConsentAge); } public override int GetBelowConsentAge() { return Tapjoy_GetBelowConsentAgeStatus (); } public override void SetUSPrivacy(string privacyConsent) { Tapjoy_SetUSPrivacy(privacyConsent); } public override string GetUSPrivacy() { return Tapjoy_GetUSPrivacy(); } public override void OptOutAdvertisingID(bool optOut) { // no op } public override bool GetOptOutAdvertisingID() { return false; } public override void ActivateUnitySupport() { // figure this out } public override void GetCurrencyBalance() { Tapjoy_GetCurrencyBalance(); } public override void SpendCurrency(int amount) { Tapjoy_SpendCurrency(amount); } public override void AwardCurrency(int amount) { Tapjoy_AwardCurrency(amount); } public override void ShowDefaultEarnedCurrencyAlert() { Tapjoy_ShowDefaultEarnedCurrencyAlert(); } // Tapjoy Placement public override void CreatePlacement(string placementGuid, string eventName) { Tapjoy_CreatePlacement(placementGuid, eventName); } public override void DismissPlacementContent() { Tapjoy_DismissPlacementContent(); } public override void RequestPlacementContent(string placementGuid) { Tapjoy_RequestPlacementContent(placementGuid); } public override void ShowPlacementContent(string placementGuid) { Tapjoy_ShowPlacementContent(placementGuid); } public override bool IsPlacementContentReady(string placementGuid) { return Tapjoy_IsPlacementContentReady(placementGuid); } public override bool IsPlacementContentAvailable(string placementGuid) { return Tapjoy_IsPlacementContentAvailable(placementGuid); } public override void SetCurrencyBalance (string placementGuid, string currencyId, int balance) { Tapjoy_SetPlacementBalance (placementGuid, currencyId, balance); } public override int GetCurrencyBalance (string placementGuid, string currencyId) { return Tapjoy_GetPlacementBalance (placementGuid, currencyId); } public override void SetRequiredAmount (string placementGuid, string currencyId, int amount) { Tapjoy_SetRequiredAmount (placementGuid, currencyId, amount); } public override int GetRequiredAmount (string placementGuid, string currencyId) { return Tapjoy_GetRequiredAmount (placementGuid, currencyId); } public override void RemovePlacement(string placementGuid) { Tapjoy_RemovePlacement(placementGuid); } public override void RequestOfferwallDiscover(string placementName, float height) { Tapjoy_RequestOfferwallDiscover(placementName, height); } public override void RequestOfferwallDiscover(string placementName, float left, float top, float width, float height) { Tapjoy_RequestOfferwallDiscoverAtPosition(placementName, left, top, width, height); } public override void ShowOfferwallDiscover() { Tapjoy_ShowOfferwallDiscover(); } public override void DestroyOfferwallDiscover() { Tapjoy_DestroyOfferwallDiscover(); } public override void SetEntryPoint(string placementGuid, TJEntryPoint entryPoint) { Tapjoy_SetEntryPoint(placementGuid, entryPoint.GetValue()); } // 5Rocks Cohorts public override void SetUserID(string userID) { Tapjoy_SetUserID(userID); } public override string GetUserID() { return Tapjoy_GetUserID(); } // Currency Callback Param public override void SetCustomParameter(string customParam) { Tapjoy_SetCustomParameter(customParam); } public override string GetCustomParameter() { return Tapjoy_GetCustomParameter(); } public override void SetUserLevel(int userLevel) { Tapjoy_SetUserLevel(userLevel); } public override int GetUserLevel() { return Tapjoy_GetUserLevel(); } public override void SetMaxLevel(int maxUserLevel) { Tapjoy_SetMaxLevel(maxUserLevel); } public override int GetMaxLevel() { return Tapjoy_GetMaxLevel(); } public override void SetUserSegment(TJSegment userSegment) { Tapjoy_SetUserSegment(userSegment); } public override int GetUserSegment() { return (int)Tapjoy_GetUserSegment(); } public override double GetScreenScale() { return Tapjoy_GetScreenScale(); } // User Tags public override void ClearUserTags() { Tapjoy_ClearUserTags(); } public override List GetUserTags() { string serializedTags = Tapjoy_GetUserTags(); JSONArray tags = JSON.Parse(serializedTags).AsArray; List tagList = new List(); for(int i=0; i