Start native SDK's from .Net side in AppCenterBehavior (#134)
* add methods to start native sdk from .net code * start from AppCenterBehavior if needed * support start native sdk's from AppCenterBehavior * fix undeclared method error
This commit is contained in:
Родитель
2e75a27daf
Коммит
5bf9633515
|
@ -25,7 +25,7 @@ public class AppCenterBehavior : MonoBehaviour
|
|||
// Make sure that App Center have only one instance.
|
||||
if (_instance != null)
|
||||
{
|
||||
Debug.LogError("App Center should have only one instance!");
|
||||
Debug.LogError("App Center Behavior should have only one instance!");
|
||||
DestroyImmediate(gameObject);
|
||||
return;
|
||||
}
|
||||
|
@ -55,36 +55,94 @@ public class AppCenterBehavior : MonoBehaviour
|
|||
PrepareEventHandlers(services);
|
||||
InvokeInitializingServices();
|
||||
AppCenter.SetWrapperSdk();
|
||||
|
||||
// On iOS we start crash service here, to give app an opportunity to assign handlers after crash and restart in Awake method
|
||||
#if UNITY_IOS
|
||||
foreach (var service in services)
|
||||
{
|
||||
var startCrashes = service.GetMethod("StartCrashes");
|
||||
if (startCrashes != null)
|
||||
startCrashes.Invoke(null, null);
|
||||
}
|
||||
#endif
|
||||
|
||||
var appSecret = AppCenter.GetSecretForPlatform(Settings.AppSecret);
|
||||
if (Settings.CustomLogUrl.UseCustomUrl)
|
||||
{
|
||||
AppCenter.CacheLogUrl(Settings.CustomLogUrl.Url);
|
||||
}
|
||||
// On iOS and Android App Center starting automatically.
|
||||
#if UNITY_EDITOR || (!UNITY_IOS && !UNITY_ANDROID)
|
||||
AppCenter.LogLevel = Settings.InitialLogLevel;
|
||||
if (Settings.CustomLogUrl.UseCustomUrl)
|
||||
var advancedSettings = GetComponent<AppCenterBehaviorAdvanced>();
|
||||
if (IsStartFromAppCenterBehavior(advancedSettings))
|
||||
{
|
||||
AppCenter.SetLogUrl(Settings.CustomLogUrl.Url);
|
||||
AppCenter.LogLevel = Settings.InitialLogLevel;
|
||||
if (Settings.CustomLogUrl.UseCustomUrl)
|
||||
{
|
||||
AppCenter.SetLogUrl(Settings.CustomLogUrl.Url);
|
||||
}
|
||||
var startupType = GetStartupType(advancedSettings);
|
||||
if (startupType != StartupType.Skip)
|
||||
{
|
||||
var appSecret = AppCenter.GetSecretForPlatform(Settings.AppSecret);
|
||||
var transmissionTargetToken = GetTransmissionTargetToken(advancedSettings);
|
||||
var appSecretString = GetAppSecretString(appSecret, transmissionTargetToken, startupType);
|
||||
if (string.IsNullOrEmpty(appSecretString))
|
||||
{
|
||||
AppCenterInternal.Start(services);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppCenterInternal.Start(appSecretString, services);
|
||||
}
|
||||
}
|
||||
}
|
||||
// On iOS we start crash service here, to give app an opportunity to assign handlers after crash and restart in Awake method
|
||||
#if UNITY_IOS
|
||||
else
|
||||
{
|
||||
foreach (var service in services)
|
||||
{
|
||||
var startCrashes = service.GetMethod("StartCrashes");
|
||||
if (startCrashes != null)
|
||||
startCrashes.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
var nativeServiceTypes = AppCenter.ServicesToNativeTypes(services);
|
||||
AppCenterInternal.Start(appSecret, nativeServiceTypes, services.Length);
|
||||
#endif
|
||||
|
||||
InvokeInitializedServices();
|
||||
}
|
||||
|
||||
private bool IsStartFromAppCenterBehavior(AppCenterBehaviorAdvanced advancedSettings)
|
||||
{
|
||||
#if UNITY_IOS
|
||||
return advancedSettings != null && advancedSettings.SettingsAdvanced != null && advancedSettings.SettingsAdvanced.StartIOSNativeSDKFromAppCenterBehavior;
|
||||
#elif UNITY_ANDROID
|
||||
return advancedSettings != null && advancedSettings.SettingsAdvanced != null && advancedSettings.SettingsAdvanced.StartAndroidNativeSDKFromAppCenterBehavior;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
private StartupType GetStartupType(AppCenterBehaviorAdvanced advancedSettings)
|
||||
{
|
||||
return advancedSettings != null && advancedSettings.SettingsAdvanced != null ?
|
||||
advancedSettings.SettingsAdvanced.GetStartupType() :
|
||||
StartupType.AppCenter;
|
||||
}
|
||||
|
||||
private string GetTransmissionTargetToken(AppCenterBehaviorAdvanced advancedSettings)
|
||||
{
|
||||
return advancedSettings != null && advancedSettings.SettingsAdvanced != null ?
|
||||
advancedSettings.SettingsAdvanced.TransmissionTargetToken :
|
||||
string.Empty;
|
||||
}
|
||||
|
||||
private string GetAppSecretString(string appSecret, string transmissionTargetToken, StartupType startupType)
|
||||
{
|
||||
#if UNITY_WSA_10_0
|
||||
return appSecret;
|
||||
#else
|
||||
switch (startupType)
|
||||
{
|
||||
default:
|
||||
case StartupType.AppCenter:
|
||||
return appSecret;
|
||||
case StartupType.NoSecret:
|
||||
return string.Empty;
|
||||
case StartupType.OneCollector:
|
||||
return string.Format("target={0}", transmissionTargetToken);
|
||||
case StartupType.Both:
|
||||
return string.Format("appsecret={0};target={1}", appSecret, transmissionTargetToken);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void PrepareEventHandlers(Type[] services)
|
||||
{
|
||||
foreach (var service in services)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
//
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[HelpURL("https://docs.microsoft.com/en-us/appcenter/sdk/crashes/unity")]
|
||||
|
@ -15,7 +14,7 @@ public class AppCenterBehaviorAdvanced : MonoBehaviour
|
|||
// Make sure that App Center have the default behavior attached.
|
||||
if (gameObject.GetComponent<AppCenterBehavior>() == null)
|
||||
{
|
||||
Debug.LogError("App Center should have the AppCenterBehavior instance attached to the game object!");
|
||||
Debug.LogError("App Center Behavior Advanced should have the App Center Behavior instance attached to the same game object.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AppCenter.Unity;
|
||||
using UnityEngine;
|
||||
|
@ -18,6 +16,19 @@ public class AppCenterSettingsAdvanced : ScriptableObject
|
|||
[Tooltip("Configure the way App Center is started. For more info on startup types refer to the documentation.")]
|
||||
public StartupType AppCenterStartupType = StartupType.Both;
|
||||
|
||||
[Tooltip("Start Android native SDK from the App Center Behavior script instead of the native plugin")]
|
||||
public bool StartAndroidNativeSDKFromAppCenterBehavior = false;
|
||||
|
||||
[Tooltip("Start iOS native SDK from the App Center Behavior script instead of the native plugin")]
|
||||
public bool StartIOSNativeSDKFromAppCenterBehavior = false;
|
||||
|
||||
public StartupType GetStartupType()
|
||||
{
|
||||
return AppCenterStartupType == StartupType.Both && string.IsNullOrEmpty(TransmissionTargetToken) ?
|
||||
StartupType.AppCenter :
|
||||
AppCenterStartupType;
|
||||
}
|
||||
|
||||
private static Assembly AppCenterAssembly
|
||||
{
|
||||
get
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
using System.IO;
|
||||
using Microsoft.AppCenter.Unity;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
using UnityEditor.Build.Reporting;
|
||||
#endif
|
||||
using Microsoft.AppCenter.Unity;
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
public class AppCenterPreBuild : IPreprocessBuildWithReport
|
||||
|
@ -25,89 +24,42 @@ public class AppCenterPreBuild : IPreprocessBuild
|
|||
{
|
||||
if (target == BuildTarget.Android)
|
||||
{
|
||||
AddStartupCodeToAndroid();
|
||||
AddStartupCode(new AppCenterSettingsMakerAndroid());
|
||||
}
|
||||
else if (target == BuildTarget.iOS)
|
||||
{
|
||||
AddStartupCodeToiOS();
|
||||
AddStartupCode(new AppCenterSettingsMakerIos());
|
||||
}
|
||||
}
|
||||
|
||||
void AddStartupCodeToAndroid()
|
||||
private void AddStartupCode(IAppCenterSettingsMaker settingsMaker)
|
||||
{
|
||||
var settings = AppCenterSettingsContext.SettingsInstance;
|
||||
var advancedSettings = AppCenterSettingsContext.SettingsInstanceAdvanced;
|
||||
var settingsMaker = new AppCenterSettingsMakerAndroid();
|
||||
settingsMaker.SetAppSecret(settings.AndroidAppSecret);
|
||||
settingsMaker.SetAppSecret(settings);
|
||||
settingsMaker.SetLogLevel((int)settings.InitialLogLevel);
|
||||
if (settings.CustomLogUrl.UseCustomUrl)
|
||||
{
|
||||
settingsMaker.SetLogUrl(settings.CustomLogUrl.Url);
|
||||
}
|
||||
if (settings.UsePush && IsAndroidPushAvailable())
|
||||
if (settings.UsePush && settingsMaker.IsPushAvailable())
|
||||
{
|
||||
settingsMaker.StartPushClass();
|
||||
settingsMaker.SetSenderId(settings.SenderId);
|
||||
if (settings.EnableFirebaseAnalytics)
|
||||
{
|
||||
settingsMaker.EnableFirebaseAnalytics();
|
||||
}
|
||||
}
|
||||
if (settings.UseAnalytics && IsAndroidAnalyticsAvailable())
|
||||
if (settings.UseAnalytics && settingsMaker.IsAnalyticsAvailable())
|
||||
{
|
||||
settingsMaker.StartAnalyticsClass();
|
||||
}
|
||||
if (settings.UseCrashes && IsAndroidCrashesAvailable())
|
||||
if (settings.UseCrashes && settingsMaker.IsCrashesAvailable())
|
||||
{
|
||||
settingsMaker.StartCrashesClass();
|
||||
}
|
||||
if (settings.UseDistribute && IsAndroidDistributeAvailable())
|
||||
{
|
||||
if (settings.CustomApiUrl.UseCustomUrl)
|
||||
{
|
||||
settingsMaker.SetApiUrl(settings.CustomApiUrl.Url);
|
||||
}
|
||||
if (settings.CustomInstallUrl.UseCustomUrl)
|
||||
{
|
||||
settingsMaker.SetInstallUrl(settings.CustomInstallUrl.Url);
|
||||
}
|
||||
settingsMaker.StartDistributeClass();
|
||||
}
|
||||
settingsMaker.SetLogLevel((int)settings.InitialLogLevel);
|
||||
if (advancedSettings != null)
|
||||
{
|
||||
settingsMaker.SetStartupType((int)advancedSettings.AppCenterStartupType);
|
||||
settingsMaker.SetTransmissionTargetToken(advancedSettings.TransmissionTargetToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsMaker.SetStartupType((int)StartupType.AppCenter);
|
||||
}
|
||||
settingsMaker.CommitSettings();
|
||||
}
|
||||
|
||||
static void AddStartupCodeToiOS()
|
||||
{
|
||||
var settings = AppCenterSettingsContext.SettingsInstance;
|
||||
var advancedSettings = AppCenterSettingsContext.SettingsInstanceAdvanced;
|
||||
var settingsMaker = new AppCenterSettingsMakerIos();
|
||||
if (settings.CustomLogUrl.UseCustomUrl)
|
||||
{
|
||||
settingsMaker.SetLogUrl(settings.CustomLogUrl.Url);
|
||||
}
|
||||
settingsMaker.SetLogLevel((int)settings.InitialLogLevel);
|
||||
settingsMaker.SetAppSecret(settings.iOSAppSecret);
|
||||
if (settings.UseCrashes && IsIOSCrashesAvailable())
|
||||
{
|
||||
settingsMaker.StartCrashesClass();
|
||||
}
|
||||
if (settings.UsePush && IsIOSPushAvailable())
|
||||
{
|
||||
settingsMaker.StartPushClass();
|
||||
}
|
||||
if (settings.UseAnalytics && IsIOSAnalyticsAvailable())
|
||||
{
|
||||
settingsMaker.StartAnalyticsClass();
|
||||
}
|
||||
if (settings.UseDistribute && IsIOSDistributeAvailable())
|
||||
if (settings.UseDistribute && settingsMaker.IsDistributeAvailable())
|
||||
{
|
||||
if (settings.CustomApiUrl.UseCustomUrl)
|
||||
{
|
||||
|
@ -121,7 +73,8 @@ public class AppCenterPreBuild : IPreprocessBuild
|
|||
}
|
||||
if (advancedSettings != null)
|
||||
{
|
||||
settingsMaker.SetStartupType((int)advancedSettings.AppCenterStartupType);
|
||||
var startupType = settingsMaker.IsStartFromAppCenterBehavior(advancedSettings) ? StartupType.Skip : advancedSettings.GetStartupType();
|
||||
settingsMaker.SetStartupType((int)startupType);
|
||||
settingsMaker.SetTransmissionTargetToken(advancedSettings.TransmissionTargetToken);
|
||||
}
|
||||
else
|
||||
|
@ -130,44 +83,4 @@ public class AppCenterPreBuild : IPreprocessBuild
|
|||
}
|
||||
settingsMaker.CommitSettings();
|
||||
}
|
||||
|
||||
static bool IsAndroidDistributeAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-distribute-release.aar");
|
||||
}
|
||||
|
||||
static bool IsAndroidPushAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-push-release.aar");
|
||||
}
|
||||
|
||||
static bool IsAndroidAnalyticsAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-analytics-release.aar");
|
||||
}
|
||||
|
||||
static bool IsAndroidCrashesAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-crashes-release.aar");
|
||||
}
|
||||
|
||||
static bool IsIOSDistributeAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Distribute");
|
||||
}
|
||||
|
||||
static bool IsIOSPushAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Push");
|
||||
}
|
||||
|
||||
static bool IsIOSAnalyticsAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Analytics");
|
||||
}
|
||||
|
||||
static bool IsIOSCrashesAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Crashes");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ public class AppCenterSettingsContext : ScriptableObject
|
|||
public const string AppCenterPath = "Assets";
|
||||
private const string SettingsPath = AppCenterPath + "/AppCenter/AppCenterSettings.asset";
|
||||
private const string AdvancedSettingsPath = AppCenterPath + "/AppCenter/AppCenterSettingsAdvanced.asset";
|
||||
|
||||
public static AppCenterSettings SettingsInstance
|
||||
{
|
||||
get
|
||||
|
@ -42,5 +43,4 @@ public class AppCenterSettingsContext : ScriptableObject
|
|||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
//
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(AppCenterSettingsAdvanced))]
|
||||
public class AppCenterSettingsEditorAdvanced : Editor
|
||||
|
@ -11,8 +11,9 @@ public class AppCenterSettingsEditorAdvanced : Editor
|
|||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("TransmissionTargetToken"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("StartAndroidNativeSDKFromAppCenterBehavior"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("StartIOSNativeSDKFromAppCenterBehavior"), new GUIContent("Start iOS Native SDK From App Center Behavior"));
|
||||
//The following line can be useful if you want to be able to configure StartupType from AppCenter Behaviour Advanced.
|
||||
//EditorGUILayout.PropertyField(serializedObject.FindProperty("AppCenterStartupType"));
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class AppCenterSettingsMakerAndroid
|
||||
public class AppCenterSettingsMakerAndroid : IAppCenterSettingsMaker
|
||||
{
|
||||
private const string AppCenterResourcesFolderPath = "Assets/Plugins/Android/res/values/";
|
||||
private const string AppCenterResourcesPath = AppCenterResourcesFolderPath + "appcenter-settings.xml";
|
||||
|
@ -52,9 +52,9 @@ public class AppCenterSettingsMakerAndroid
|
|||
_resourceValues[UseCustomLogUrlKey] = true.ToString();
|
||||
}
|
||||
|
||||
public void SetAppSecret(string appSecret)
|
||||
public void SetAppSecret(AppCenterSettings settings)
|
||||
{
|
||||
_resourceValues[AppSecretKey] = appSecret;
|
||||
_resourceValues[AppSecretKey] = settings.AndroidAppSecret;
|
||||
}
|
||||
|
||||
public void SetTransmissionTargetToken(string transmissionTargetToken)
|
||||
|
@ -112,4 +112,29 @@ public class AppCenterSettingsMakerAndroid
|
|||
}
|
||||
XmlResourceHelper.WriteXmlResource(AppCenterResourcesPath, _resourceValues);
|
||||
}
|
||||
|
||||
public bool IsStartFromAppCenterBehavior(AppCenterSettingsAdvanced advancedSettings)
|
||||
{
|
||||
return advancedSettings.StartAndroidNativeSDKFromAppCenterBehavior;
|
||||
}
|
||||
|
||||
public bool IsAnalyticsAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-analytics-release.aar");
|
||||
}
|
||||
|
||||
public bool IsCrashesAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-crashes-release.aar");
|
||||
}
|
||||
|
||||
public bool IsDistributeAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-distribute-release.aar");
|
||||
}
|
||||
|
||||
public bool IsPushAvailable()
|
||||
{
|
||||
return File.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/Android/appcenter-push-release.aar");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
using System.IO;
|
||||
|
||||
public class AppCenterSettingsMakerIos
|
||||
public class AppCenterSettingsMakerIos : IAppCenterSettingsMaker
|
||||
{
|
||||
private const string TemplateFilePath = AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Core/AppCenterStarter.original";
|
||||
private const string TargetFilePath = AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Core/AppCenterStarter.m";
|
||||
|
@ -46,9 +46,9 @@ public class AppCenterSettingsMakerIos
|
|||
_loaderFileText = _loaderFileText.Replace(LogUrlSearchText, logUrl);
|
||||
}
|
||||
|
||||
public void SetAppSecret(string appSecret)
|
||||
public void SetAppSecret(AppCenterSettings settings)
|
||||
{
|
||||
_loaderFileText = _loaderFileText.Replace(AppSecretSearchText, appSecret);
|
||||
_loaderFileText = _loaderFileText.Replace(AppSecretSearchText, settings.iOSAppSecret);
|
||||
}
|
||||
|
||||
public void SetTransmissionTargetToken(string transmissionTargetToken)
|
||||
|
@ -88,6 +88,14 @@ public class AppCenterSettingsMakerIos
|
|||
AddToken(UsePushToken);
|
||||
}
|
||||
|
||||
public void SetSenderId(string senderId)
|
||||
{
|
||||
}
|
||||
|
||||
public void EnableFirebaseAnalytics()
|
||||
{
|
||||
}
|
||||
|
||||
public void CommitSettings()
|
||||
{
|
||||
File.WriteAllText(TargetFilePath, _loaderFileText);
|
||||
|
@ -98,4 +106,29 @@ public class AppCenterSettingsMakerIos
|
|||
var tokenText = "#define " + token + "\n";
|
||||
_loaderFileText = tokenText + _loaderFileText;
|
||||
}
|
||||
|
||||
public bool IsStartFromAppCenterBehavior(AppCenterSettingsAdvanced advancedSettings)
|
||||
{
|
||||
return advancedSettings.StartIOSNativeSDKFromAppCenterBehavior;
|
||||
}
|
||||
|
||||
public bool IsAnalyticsAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Analytics");
|
||||
}
|
||||
|
||||
public bool IsCrashesAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Crashes");
|
||||
}
|
||||
|
||||
public bool IsDistributeAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Distribute");
|
||||
}
|
||||
|
||||
public bool IsPushAvailable()
|
||||
{
|
||||
return Directory.Exists(AppCenterSettingsContext.AppCenterPath + "/AppCenter/Plugins/iOS/Push");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the MIT license.
|
||||
|
||||
public interface IAppCenterSettingsMaker
|
||||
{
|
||||
bool IsAnalyticsAvailable();
|
||||
bool IsCrashesAvailable();
|
||||
bool IsDistributeAvailable();
|
||||
bool IsPushAvailable();
|
||||
void StartAnalyticsClass();
|
||||
void StartCrashesClass();
|
||||
void StartDistributeClass();
|
||||
void StartPushClass();
|
||||
void SetAppSecret(AppCenterSettings settings);
|
||||
void SetTransmissionTargetToken(string transmissionTargetToken);
|
||||
void SetLogLevel(int logLevel);
|
||||
bool IsStartFromAppCenterBehavior(AppCenterSettingsAdvanced advancedSettings);
|
||||
void SetStartupType(int startupType);
|
||||
void SetSenderId(string senderId);
|
||||
void SetLogUrl(string logUrl);
|
||||
void SetApiUrl(string apiUrl);
|
||||
void SetInstallUrl(string installUrl);
|
||||
void EnableFirebaseAnalytics();
|
||||
void CommitSettings();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a40c6c75c7d49cd4ab84b0d6d68a509f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -55,8 +55,9 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
AndroidJavaObject future = _appCenter.CallStatic<AndroidJavaObject>("getInstallId");
|
||||
var javaUUIDtask = new AppCenterTask<AndroidJavaObject>(future);
|
||||
var stringTask = new AppCenterTask<string>();
|
||||
javaUUIDtask.ContinueWith(t => {
|
||||
var installId = t.Result.Call<string>("toString");
|
||||
javaUUIDtask.ContinueWith(t =>
|
||||
{
|
||||
var installId = t.Result == null ? null : t.Result.Call<string>("toString");
|
||||
stringTask.SetResult(installId);
|
||||
});
|
||||
return stringTask;
|
||||
|
@ -90,10 +91,34 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
wrapperSdkObject.Call("setLiveUpdatePackageHash", liveUpdatePackageHash);
|
||||
_appCenter.CallStatic("setWrapperSdk", wrapperSdkObject);
|
||||
}
|
||||
|
||||
|
||||
public static void Start(string appSecret, Type[] services)
|
||||
{
|
||||
var nativeServiceTypes = ServicesToNativeTypes(services);
|
||||
var rawAppSecretString = AndroidJNI.NewStringUTF(appSecret);
|
||||
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "start", "(Landroid/app/Application;Ljava/lang/String;[Ljava/lang/Class;)V");
|
||||
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
|
||||
{
|
||||
new jvalue { l = GetAndroidApplication().GetRawObject() },
|
||||
new jvalue { l = rawAppSecretString },
|
||||
new jvalue { l = nativeServiceTypes }
|
||||
});
|
||||
}
|
||||
|
||||
public static void Start(Type[] services)
|
||||
{
|
||||
var nativeServiceTypes = ServicesToNativeTypes(services);
|
||||
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "start", "(Landroid/app/Application;[Ljava/lang/Class;)V");
|
||||
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
|
||||
{
|
||||
new jvalue { l = GetAndroidApplication().GetRawObject() },
|
||||
new jvalue { l = nativeServiceTypes }
|
||||
});
|
||||
}
|
||||
|
||||
private static AndroidJavaObject GetAndroidContext()
|
||||
{
|
||||
if (_context != null)
|
||||
if (_context != null)
|
||||
{
|
||||
return _context;
|
||||
}
|
||||
|
@ -108,10 +133,23 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
var startMethod = AndroidJNI.GetStaticMethodID(_appCenter.GetRawClass(), "startFromLibrary", "(Landroid/content/Context;[Ljava/lang/Class;)V");
|
||||
AndroidJNI.CallStaticVoidMethod(_appCenter.GetRawClass(), startMethod, new jvalue[]
|
||||
{
|
||||
new jvalue { l = GetAndroidContext().GetRawObject() },
|
||||
new jvalue { l = servicesArray[0] }
|
||||
new jvalue { l = GetAndroidContext().GetRawObject() },
|
||||
new jvalue { l = servicesArray[0] }
|
||||
});
|
||||
}
|
||||
|
||||
public static IntPtr ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
var classClass = AndroidJNI.FindClass("java/lang/Class");
|
||||
var array = AndroidJNI.NewObjectArray(services.Length, classClass, classClass);
|
||||
int currentIdx = 0;
|
||||
foreach (var serviceType in services)
|
||||
{
|
||||
var nativeType = (IntPtr)serviceType.GetMethod("GetNativeType").Invoke(null, null);
|
||||
AndroidJNI.SetObjectArrayElement(array, currentIdx++, nativeType);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -38,9 +38,16 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
{
|
||||
}
|
||||
|
||||
public static void Start(string appSecret, Type[] services)
|
||||
{
|
||||
}
|
||||
|
||||
public static void Start(Type[] services)
|
||||
{
|
||||
}
|
||||
|
||||
public static void StartFromLibrary(ServiceType[] services)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void SetLogLevel(int logLevel)
|
||||
|
|
|
@ -99,59 +99,6 @@ namespace Microsoft.AppCenter.Unity
|
|||
get { return AppCenterInternal.IsConfigured(); }
|
||||
}
|
||||
|
||||
#if UNITY_IOS
|
||||
public static ServiceType[] ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
IntPtr[] classPointers = new IntPtr[services.Length];
|
||||
int currentIdx = 0;
|
||||
foreach (var serviceType in services)
|
||||
{
|
||||
IntPtr nativeType = (IntPtr)serviceType.GetMethod("GetNativeType").Invoke(null, null);
|
||||
classPointers[currentIdx++] = nativeType;
|
||||
}
|
||||
return classPointers;
|
||||
}
|
||||
#elif UNITY_ANDROID
|
||||
public static ServiceType[] ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
var classClass = AndroidJNI.FindClass("java/lang/Class");
|
||||
var array = AndroidJNI.NewObjectArray(services.Length, classClass, classClass);
|
||||
int currentIdx = 0;
|
||||
foreach (var serviceType in services)
|
||||
{
|
||||
ServiceType nativeType = (ServiceType)serviceType.GetMethod("GetNativeType").Invoke(null, null);
|
||||
AndroidJNI.SetObjectArrayElement(array, currentIdx++, nativeType);
|
||||
}
|
||||
return new ServiceType[] { array };
|
||||
}
|
||||
#elif UNITY_WSA_10_0
|
||||
public static ServiceType[] ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
//TODO after all namespaces are changed to be in Microsoft.AppCenter.Unity,
|
||||
//TODO remove case where 'method == null'
|
||||
var nativeTypes = new ServiceType[services.Length];
|
||||
for (var i = 0; i < services.Length; ++i)
|
||||
{
|
||||
var method = services[i].GetMethod("GetNativeType");
|
||||
if (method == null)
|
||||
{
|
||||
nativeTypes[i] = services[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
nativeTypes[i] = (ServiceType)method.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
return nativeTypes;
|
||||
}
|
||||
#else
|
||||
public static ServiceType[] ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Set the custom properties.
|
||||
/// </summary>
|
||||
|
@ -164,9 +111,7 @@ namespace Microsoft.AppCenter.Unity
|
|||
|
||||
public static void SetWrapperSdk()
|
||||
{
|
||||
AppCenterInternal.SetWrapperSdk(WrapperSdk.WrapperSdkVersion,
|
||||
WrapperSdk.Name,
|
||||
WrapperSdk.WrapperRuntimeVersion, null, null, null);
|
||||
AppCenterInternal.SetWrapperSdk(WrapperSdk.WrapperSdkVersion, WrapperSdk.Name, WrapperSdk.WrapperRuntimeVersion, null, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -22,10 +22,18 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
UWPAppCenter.Configure(appSecret);
|
||||
}
|
||||
|
||||
public static void Start(string appSecret, Type[] services, int numServices)
|
||||
public static void Start(string appSecret, Type[] services)
|
||||
{
|
||||
var nativeServiceTypes = ServicesToNativeTypes(services);
|
||||
Prepare();
|
||||
UWPAppCenter.Start(appSecret, services);
|
||||
UWPAppCenter.Start(appSecret, nativeServiceTypes);
|
||||
}
|
||||
|
||||
public static void Start(Type[] services)
|
||||
{
|
||||
var nativeServiceTypes = ServicesToNativeTypes(services);
|
||||
Prepare();
|
||||
UWPAppCenter.Start(nativeServiceTypes);
|
||||
}
|
||||
|
||||
public static string GetSdkVersion()
|
||||
|
@ -80,7 +88,8 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
Prepare();
|
||||
var installIdTask = UWPAppCenter.GetInstallIdAsync();
|
||||
var stringTask = new AppCenterTask<string>();
|
||||
installIdTask.ContinueWith(t => {
|
||||
installIdTask.ContinueWith(t =>
|
||||
{
|
||||
var installId = t.Result?.ToString();
|
||||
stringTask.SetResult(installId);
|
||||
});
|
||||
|
@ -150,9 +159,28 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
}
|
||||
}
|
||||
|
||||
public static void StartFromLibrary(Type[] services)
|
||||
public static void StartFromLibrary(Type[] services)
|
||||
{
|
||||
}
|
||||
|
||||
public static Type[] ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
//TODO after all namespaces are changed to be in Microsoft.AppCenter.Unity,
|
||||
//TODO remove case where 'method == null'
|
||||
var nativeTypes = new Type[services.Length];
|
||||
for (var i = 0; i < services.Length; ++i)
|
||||
{
|
||||
var method = services[i].GetMethod("GetNativeType");
|
||||
if (method == null)
|
||||
{
|
||||
nativeTypes[i] = services[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
nativeTypes[i] = (Type)method.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
return nativeTypes;
|
||||
}
|
||||
|
||||
private static void Prepare()
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
{
|
||||
return appcenter_unity_get_log_level();
|
||||
}
|
||||
|
||||
|
||||
public static string GetSdkVersion()
|
||||
{
|
||||
return appcenter_unity_get_sdk_version();
|
||||
|
@ -66,18 +66,42 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
string liveUpdatePackageHash)
|
||||
{
|
||||
appcenter_unity_set_wrapper_sdk(wrapperSdkVersion,
|
||||
wrapperSdkName,
|
||||
wrapperRuntimeVersion,
|
||||
liveUpdateReleaseLabel,
|
||||
liveUpdateDeploymentKey,
|
||||
liveUpdatePackageHash);
|
||||
wrapperSdkName,
|
||||
wrapperRuntimeVersion,
|
||||
liveUpdateReleaseLabel,
|
||||
liveUpdateDeploymentKey,
|
||||
liveUpdatePackageHash);
|
||||
}
|
||||
|
||||
public static void StartFromLibrary(IntPtr[] services)
|
||||
public static void Start(string appSecret, Type[] services)
|
||||
{
|
||||
var nativeServiceTypes = ServicesToNativeTypes(services);
|
||||
appcenter_unity_start(appSecret, nativeServiceTypes, nativeServiceTypes.Length);
|
||||
}
|
||||
|
||||
public static void Start(Type[] services)
|
||||
{
|
||||
var nativeServiceTypes = ServicesToNativeTypes(services);
|
||||
appcenter_unity_start_no_secret(nativeServiceTypes, nativeServiceTypes.Length);
|
||||
}
|
||||
|
||||
public static void StartFromLibrary(IntPtr[] services)
|
||||
{
|
||||
appcenter_unity_start_from_library(services, services.Length);
|
||||
}
|
||||
|
||||
private static IntPtr[] ServicesToNativeTypes(Type[] services)
|
||||
{
|
||||
var classPointers = new IntPtr[services.Length];
|
||||
int currentIdx = 0;
|
||||
foreach (var serviceType in services)
|
||||
{
|
||||
IntPtr nativeType = (IntPtr)serviceType.GetMethod("GetNativeType").Invoke(null, null);
|
||||
classPointers[currentIdx++] = nativeType;
|
||||
}
|
||||
return classPointers;
|
||||
}
|
||||
|
||||
#region External
|
||||
|
||||
[DllImport("__Internal")]
|
||||
|
@ -104,6 +128,12 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
[DllImport("__Internal")]
|
||||
private static extern string appcenter_unity_get_install_id();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void appcenter_unity_start(string appSecret, IntPtr[] classes, int count);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void appcenter_unity_start_no_secret(IntPtr[] classes, int count);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void appcenter_unity_start_from_library(IntPtr[] classes, int count);
|
||||
|
||||
|
@ -112,11 +142,11 @@ namespace Microsoft.AppCenter.Unity.Internal
|
|||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void appcenter_unity_set_wrapper_sdk(string wrapperSdkVersion,
|
||||
string wrapperSdkName,
|
||||
string wrapperRuntimeVersion,
|
||||
string liveUpdateReleaseLabel,
|
||||
string liveUpdateDeploymentKey,
|
||||
string liveUpdatePackageHash);
|
||||
string wrapperSdkName,
|
||||
string wrapperRuntimeVersion,
|
||||
string liveUpdateReleaseLabel,
|
||||
string liveUpdateDeploymentKey,
|
||||
string liveUpdatePackageHash);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace Microsoft.AppCenter.Unity.Distribute.Internal
|
|||
|
||||
private static void Initialize()
|
||||
{
|
||||
appcenter_unity_distribute_set_delegate();
|
||||
del = ReleaseAvailableFunc;
|
||||
appcenter_unity_distribute_set_release_available_impl(del);
|
||||
}
|
||||
|
@ -107,6 +108,9 @@ namespace Microsoft.AppCenter.Unity.Distribute.Internal
|
|||
[DllImport("__Internal")]
|
||||
private static extern void appcenter_unity_distribute_replay_release_available();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void appcenter_unity_distribute_set_delegate();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ static const int kMSStartupType = 0/*STARTUP_TYPE*/;
|
|||
#ifdef APPCENTER_UNITY_USE_CUSTOM_INSTALL_URL
|
||||
[MSDistribute setInstallUrl:kMSCustomInstallUrl];
|
||||
#endif // APPCENTER_UNITY_USE_CUSTOM_INSTALL_URL
|
||||
[MSDistribute setDelegate:[UnityDistributeDelegate sharedInstance]];
|
||||
[classes addObject:MSDistribute.class];
|
||||
|
||||
#endif // APPCENTER_UNITY_USE_DISTRIBUTE
|
||||
|
@ -89,15 +88,12 @@ static const int kMSStartupType = 0/*STARTUP_TYPE*/;
|
|||
[MSAppCenter start:kMSAppSecret withServices:classes];
|
||||
break;
|
||||
case ONECOLLECTOR:
|
||||
[MSAppCenter start:[NSString stringWithFormat:@"target=%@",
|
||||
kMSTargetToken]
|
||||
[MSAppCenter start:[NSString stringWithFormat:@"target=%@", kMSTargetToken]
|
||||
withServices:classes];
|
||||
break;
|
||||
case BOTH:
|
||||
[MSAppCenter start:[NSString stringWithFormat:@"appsecret=%@;target=%@",
|
||||
kMSAppSecret,
|
||||
kMSTargetToken]
|
||||
withServices:classes];
|
||||
[MSAppCenter start:[NSString stringWithFormat:@"appsecret=%@;target=%@", kMSAppSecret, kMSTargetToken]
|
||||
withServices:classes];
|
||||
break;
|
||||
case NONE:
|
||||
[MSAppCenter startWithServices:classes];
|
||||
|
|
|
@ -12,11 +12,13 @@ extern "C" void appcenter_unity_set_enabled(bool isEnabled);
|
|||
extern "C" bool appcenter_unity_is_enabled();
|
||||
extern "C" const char* appcenter_unity_get_sdk_version();
|
||||
extern "C" const char* appcenter_unity_get_install_id();
|
||||
extern "C" void appcenter_unity_start(const char* appSecret, void** services, int count);
|
||||
extern "C" void appcenter_unity_start_no_secret(void** services, int count);
|
||||
extern "C" void appcenter_unity_start_from_library(void** services, int count);
|
||||
extern "C" void appcenter_unity_set_custom_properties(MSCustomProperties* properties);
|
||||
extern "C" void appcenter_unity_set_wrapper_sdk(const char* wrapperSdkVersion,
|
||||
const char* wrapperSdkName,
|
||||
const char* wrapperRuntimeVersion,
|
||||
const char* liveUpdateReleaseLabel,
|
||||
const char* liveUpdateDeploymentKey,
|
||||
const char* liveUpdatePackageHash);
|
||||
const char* wrapperSdkName,
|
||||
const char* wrapperRuntimeVersion,
|
||||
const char* liveUpdateReleaseLabel,
|
||||
const char* liveUpdateDeploymentKey,
|
||||
const char* liveUpdatePackageHash);
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
#import <AppCenter/AppCenter.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NSMutableArray<Class>* get_services_array(void** services, int count) {
|
||||
NSMutableArray<Class>* servicesArray = [NSMutableArray new];
|
||||
for (int i = 0; i < count; i++) {
|
||||
[servicesArray addObject:(Class)CFBridgingRelease(services[i])];
|
||||
}
|
||||
return servicesArray;
|
||||
}
|
||||
|
||||
void appcenter_unity_set_log_level(int logLevel)
|
||||
{
|
||||
[MSAppCenter setLogLevel:(MSLogLevel)logLevel];
|
||||
|
@ -32,12 +40,19 @@ void appcenter_unity_set_enabled(bool isEnabled)
|
|||
[MSAppCenter setEnabled:isEnabled];
|
||||
}
|
||||
|
||||
void appcenter_unity_start(const char* appSecret, void** services, int count) {
|
||||
NSMutableArray<Class>* servicesArray = get_services_array(services, count);
|
||||
[MSAppCenter start:appcenter_unity_cstr_to_ns_string(appSecret) withServices:servicesArray];
|
||||
}
|
||||
|
||||
void appcenter_unity_start_no_secret(void** services, int count) {
|
||||
NSMutableArray<Class>* servicesArray = get_services_array(services, count);
|
||||
[MSAppCenter startWithServices:servicesArray];
|
||||
}
|
||||
|
||||
void appcenter_unity_start_from_library(void** services, int count) {
|
||||
NSMutableArray<Class>* mutableClasses = [NSMutableArray new];
|
||||
for (int i = 0; i < count; i++) {
|
||||
[mutableClasses addObject:(Class)CFBridgingRelease(services[i])];
|
||||
}
|
||||
[MSAppCenter startFromLibraryWithServices:mutableClasses];
|
||||
NSMutableArray<Class>* servicesArray = get_services_array(services, count);
|
||||
[MSAppCenter startFromLibraryWithServices:servicesArray];
|
||||
}
|
||||
|
||||
bool appcenter_unity_is_enabled()
|
||||
|
@ -47,7 +62,7 @@ bool appcenter_unity_is_enabled()
|
|||
|
||||
const char* appcenter_unity_get_install_id()
|
||||
{
|
||||
NSString *uuidString = [[MSAppCenter installId] UUIDString];
|
||||
NSString *uuidString = [[MSAppCenter installId] UUIDString];
|
||||
return appcenter_unity_ns_string_to_cstr(uuidString);
|
||||
}
|
||||
|
||||
|
@ -62,11 +77,11 @@ void appcenter_unity_set_custom_properties(MSCustomProperties* properties)
|
|||
}
|
||||
|
||||
void appcenter_unity_set_wrapper_sdk(const char* wrapperSdkVersion,
|
||||
const char* wrapperSdkName,
|
||||
const char* wrapperRuntimeVersion,
|
||||
const char* liveUpdateReleaseLabel,
|
||||
const char* liveUpdateDeploymentKey,
|
||||
const char* liveUpdatePackageHash)
|
||||
const char* wrapperSdkName,
|
||||
const char* wrapperRuntimeVersion,
|
||||
const char* liveUpdateReleaseLabel,
|
||||
const char* liveUpdateDeploymentKey,
|
||||
const char* liveUpdatePackageHash)
|
||||
{
|
||||
MSWrapperSdk *wrapperSdk = [[MSWrapperSdk alloc]
|
||||
initWithWrapperSdkVersion:appcenter_unity_cstr_to_ns_string(wrapperSdkVersion)
|
||||
|
|
|
@ -16,5 +16,6 @@ extern "C" void appcenter_unity_distribute_set_api_url(char* apiUrl);
|
|||
extern "C" void appcenter_unity_distribute_notify_update_action(int updateAction);
|
||||
extern "C" void appcenter_unity_distribute_replay_release_available();
|
||||
extern "C" void appcenter_unity_distribute_set_release_available_impl(ReleaseAvailableFunction handler);
|
||||
extern "C" void appcenter_unity_distribute_set_delegate();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,3 +45,8 @@ void appcenter_unity_distribute_replay_release_available()
|
|||
{
|
||||
[[UnityDistributeDelegate sharedInstance] replayReleaseAvailable];
|
||||
}
|
||||
|
||||
void appcenter_unity_distribute_set_delegate()
|
||||
{
|
||||
[MSDistribute setDelegate:[UnityDistributeDelegate sharedInstance]];
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче