From f0981c62c3620487d95f226151a7a6b6b65599c2 Mon Sep 17 00:00:00 2001 From: Ben Baron Date: Fri, 1 Apr 2022 15:38:48 -0500 Subject: [PATCH] fix: iOS build issues (#17) --- Assets/Editor/MParticleBuildPostprocessor.cs | 34 +++++++++++++ .../Editor/PostprocessBuildPlayer_mParticle | 49 ------------------- Assets/Editor/mParticleBuildPostprocessor.cs | 47 ------------------ Assets/Plugins/iOS/mParticleUnity.h | 2 +- Assets/Plugins/iOS/mParticleUnity.m | 10 +--- buildscript.sh | 2 +- 6 files changed, 37 insertions(+), 107 deletions(-) create mode 100644 Assets/Editor/MParticleBuildPostprocessor.cs delete mode 100755 Assets/Editor/PostprocessBuildPlayer_mParticle delete mode 100644 Assets/Editor/mParticleBuildPostprocessor.cs diff --git a/Assets/Editor/MParticleBuildPostprocessor.cs b/Assets/Editor/MParticleBuildPostprocessor.cs new file mode 100644 index 0000000..72990d1 --- /dev/null +++ b/Assets/Editor/MParticleBuildPostprocessor.cs @@ -0,0 +1,34 @@ +using UnityEditor; +using UnityEditor.Callbacks; +using UnityEditor.iOS.Xcode; +using UnityEditor.iOS.Xcode.Extensions; + +namespace mParticle { + public class BuildPostProcessor + { + [PostProcessBuild] + public static void OnPostProcessBuild(BuildTarget target, string path) + { + if (target == BuildTarget.iOS) + { + // Get project into C# + var projectPath = PBXProject.GetPBXProjectPath(path); + var project = new PBXProject(); + project.ReadFromFile(projectPath); + + // Fix Xcode build settings + var projectGUID = project.ProjectGuid(); + project.SetBuildProperty(projectGUID, "VALIDATE_WORKSPACE", "YES"); + project.SetBuildProperty(projectGUID, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES"); + + // Embed mParticle framework + var mainTargetGUID = project.GetUnityMainTargetGuid(); + var frameworkFileGUID = project.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/mParticle_Apple_SDK.framework"); + project.AddFileToEmbedFrameworks(mainTargetGUID, frameworkFileGUID); + + // Overwrite + project.WriteToFile(projectPath); + } + } + } +} \ No newline at end of file diff --git a/Assets/Editor/PostprocessBuildPlayer_mParticle b/Assets/Editor/PostprocessBuildPlayer_mParticle deleted file mode 100755 index 27e4774..0000000 --- a/Assets/Editor/PostprocessBuildPlayer_mParticle +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env ruby -require 'rubygems' - -gem "xcodeproj", "~> 1.5.4" - -require 'xcodeproj' -require 'pathname' -require 'fileutils' - -# Getting a reference to the Xcode project -unity_project_root_path = File.expand_path(File.dirname($0)) + "/../../iOS" -build_path = (ARGV[0]) ? ARGV[0] : unity_project_root_path # + "/build" -xcode_project_path = build_path + "/Unity-iPhone.xcodeproj" -xcode_project = Xcodeproj::Project.open(xcode_project_path) -xcode_project.initialize_from_file() - -# System frameworks and libraries needed by mParticle -system_frameworks = ["Accounts", "AdSupport", "CoreTelephony", "Foundation", "Security", "Social", "SystemConfiguration", "UIKit", "iAd", "UserNotifications"] -system_libraries = ["sqlite3", "z"] - -# Iterate through each project target and adds: system frameworks, libraries, and -ObjC -xcode_project.targets.each do |target| - target.add_system_framework(system_frameworks) - - target.add_system_library(system_libraries) - - build_configurations = target.build_configurations - build_configurations.each do |build_configuration| - contains_objc = false - other_linker_flags = target.build_settings(build_configuration.name)["OTHER_LDFLAGS"] - if other_linker_flags - other_linker_flags.each do |linker_flag| - if linker_flag.eql? "-ObjC" then - contains_objc = true - break - end - end - else - other_linker_flags = [] - end - - if !contains_objc then - other_linker_flags << "-ObjC" - end - end -end - -# Saves Xcode project -xcode_project.save() diff --git a/Assets/Editor/mParticleBuildPostprocessor.cs b/Assets/Editor/mParticleBuildPostprocessor.cs deleted file mode 100644 index ce52466..0000000 --- a/Assets/Editor/mParticleBuildPostprocessor.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.IO; -using System.Diagnostics; -using System.Collections; -using System.Collections.Generic; - -using UnityEngine; -using UnityEditor; -using UnityEditor.Callbacks; - -namespace mParticle { - - public class BuildPostprocessor : MonoBehaviour - { - [PostProcessBuildAttribute(-1000)] - public static void OnPostprocessBuild(BuildTarget target, string pathToBuild) - { - UnityEngine.Debug.Log("Beginning postprocess: "+pathToBuild); - - string player = target.ToString() == "iOS" ? "iPhone" : target.ToString(); - string arguments = String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\"", pathToBuild, - player, "", PlayerSettings.companyName, PlayerSettings.productName, - PlayerSettings.defaultScreenWidth, PlayerSettings.defaultScreenHeight); - - UnityEngine.Debug.Log("Starting script: ruby " + Application.dataPath + "/Editor/PostprocessBuildPlayer_mParticle" + " " + arguments); - - Process process = new Process(); - process.StartInfo.FileName = "ruby"; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.Arguments = "\"" + Application.dataPath + "/Editor/PostprocessBuildPlayer_mParticle\"" + " " + arguments; - process.Start(); - - // Synchronously read the standard output of the spawned process. - StreamReader reader = process.StandardOutput; - string output = reader.ReadToEnd(); - - // Write the redirected output to this application's window. - Console.WriteLine(output); - - process.WaitForExit(); - process.Close(); - - UnityEngine.Debug.Log("Done postprocess"); - } - } -} \ No newline at end of file diff --git a/Assets/Plugins/iOS/mParticleUnity.h b/Assets/Plugins/iOS/mParticleUnity.h index a46f431..415ac06 100644 --- a/Assets/Plugins/iOS/mParticleUnity.h +++ b/Assets/Plugins/iOS/mParticleUnity.h @@ -9,7 +9,7 @@ void _SetUploadInterval(int uploadInterval); void _LogEvent(const char *mpEvent); void _LogCommerceEvent(const char *commerceEventJSON); void _LogScreen(const char *screenName); -void _SetATTStatus(int status, double timestamp) +void _SetATTStatus(int status, double timestamp); void _LeaveBreadcrumb(const char *breadcrumbName); diff --git a/Assets/Plugins/iOS/mParticleUnity.m b/Assets/Plugins/iOS/mParticleUnity.m index 29178c1..696046f 100644 --- a/Assets/Plugins/iOS/mParticleUnity.m +++ b/Assets/Plugins/iOS/mParticleUnity.m @@ -202,7 +202,7 @@ void _LogScreen(const char *screenName) { } void _SetATTStatus(int status, double timestamp) { - [[MParticle sharedInstance] setATTStatus:status withATTStatusTimestampMillis:timestamp]; + [[MParticle sharedInstance] setATTStatus:status withATTStatusTimestampMillis:@(timestamp)]; } void _LeaveBreadcrumb(const char *breadcrumbName) { @@ -540,14 +540,6 @@ + (MPIdentityApiRequest *) MPIdentityApiRequest:(NSDictionary *)identityRequestD [identityRequest setIdentity:identities[key] identityType:(MPIdentity)[key integerValue]]; } } - if ([[identityRequestDict allKeys]containsObject:@"UserAliasUUID"]) { - identityRequest.onUserAlias = ^(MParticleUser * _Nonnull previousUser, MParticleUser * _Nonnull newUser) { - NSDictionary *aliasDictionary = @{@"CallbackUuid": identityRequestDict[@"UserAliasUUID"], - @"PreviousMpid": [previousUser.userId stringValue], - @"NewMpid": [newUser.userId stringValue]}; - UnitySendMessage("MParticle", "OnUserAlias", toChar(jsonWithDictionary(aliasDictionary))); - }; - } return identityRequest; } diff --git a/buildscript.sh b/buildscript.sh index f9f0a29..67283f6 100755 --- a/buildscript.sh +++ b/buildscript.sh @@ -31,5 +31,5 @@ project_dir=${PWD} Assets/Plugins/iOS/MParticleUnity.h \ Assets/Plugins/iOS/MParticleUnity.m \ Assets/Plugins/iOS/mParticle_Apple_SDK.framework \ - Assets/Editor/PostprocessBuildPlayer_mParticle \ + Assets/Editor/MParticleBuildPostprocessor.cs \ mParticle.unitypackage -nographics -batchmode -quit;