Support iOS crash reporting

This commit is contained in:
2026-06-12 16:42:45 +08:00
parent e0bf4de792
commit 65b9f47d91
10 changed files with 378 additions and 54 deletions

View File

@@ -7,3 +7,15 @@
### 修复 ### 修复
* 优化package.json文件 * 优化package.json文件
# [1.0.2]
### 新增
* 支持 iOS 平台 Bugly SDK 桥接。
* iOS 导出 Xcode 工程时自动写入 `pod 'Bugly', '~> 2.6'` 依赖。
### 调整
* Unity 工程版本升级到 2022.3.62f3c1。
* package.json 的 Unity 兼容版本调整为 2022.3。

View File

@@ -0,0 +1,65 @@
#if UNITY_IOS
using System;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Editor
{
public static class CrashPostProcessBuildIOS
{
private const string PodLine = " pod 'Bugly', '~> 2.6'";
private const string UnityFrameworkTarget = "target 'UnityFramework' do";
[PostProcessBuild(980)]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
if (target != BuildTarget.iOS)
{
return;
}
EnsureBuglyPod(pathToBuiltProject);
}
private static void EnsureBuglyPod(string pathToBuiltProject)
{
string podfilePath = Path.Combine(pathToBuiltProject, "Podfile");
string content = File.Exists(podfilePath) ? File.ReadAllText(podfilePath) : string.Empty;
if (content.Contains("pod 'Bugly'") || content.Contains("pod \"Bugly\""))
{
return;
}
if (string.IsNullOrWhiteSpace(content))
{
File.WriteAllText(podfilePath,
"platform :ios, '9.0'" + Environment.NewLine +
Environment.NewLine +
UnityFrameworkTarget + Environment.NewLine +
PodLine + Environment.NewLine +
"end" + Environment.NewLine);
}
else if (content.Contains(UnityFrameworkTarget))
{
content = content.Replace(UnityFrameworkTarget, UnityFrameworkTarget + Environment.NewLine + PodLine);
File.WriteAllText(podfilePath, content);
}
else
{
File.AppendAllText(podfilePath,
Environment.NewLine +
UnityFrameworkTarget + Environment.NewLine +
PodLine + Environment.NewLine +
"end" + Environment.NewLine);
}
Debug.Log("CrashReport iOS 已写入 Bugly CocoaPods 依赖,请在 Xcode 构建前执行 pod install。");
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 723804e1f52549b68c68e8c16f02ff90
timeCreated: 1781265600

8
Assets/Plugins/iOS.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eaf538d898ef490593642d0b031c7b85
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,190 @@
#import <Foundation/Foundation.h>
#if __has_include(<Bugly/Bugly.h>)
#import <Bugly/Bugly.h>
#define FOLDCC_BUGLY_IOS_AVAILABLE 1
#else
#define FOLDCC_BUGLY_IOS_AVAILABLE 0
#endif
static NSString *FoldCCBuglyString(const char *value)
{
if (value == NULL)
{
return @"";
}
NSString *result = [NSString stringWithUTF8String:value];
return result == nil ? @"" : result;
}
static NSArray *FoldCCBuglyStackFrames(NSString *stackTrace)
{
if (stackTrace.length == 0)
{
return @[];
}
NSArray *lines = [stackTrace componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSMutableArray *frames = [NSMutableArray arrayWithCapacity:lines.count];
for (NSString *line in lines)
{
NSString *trimmed = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (trimmed.length > 0)
{
[frames addObject:trimmed];
}
}
return frames;
}
static NSDictionary *FoldCCBuglyExtraInfo(NSString *extras)
{
if (extras.length == 0)
{
return @{};
}
NSData *data = [extras dataUsingEncoding:NSUTF8StringEncoding];
id parsed = data == nil ? nil : [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([parsed isKindOfClass:[NSDictionary class]])
{
return parsed;
}
return @{ @"UnityExtraInfo" : extras };
}
#if FOLDCC_BUGLY_IOS_AVAILABLE
static NSString *s_channel = nil;
static NSString *s_version = nil;
static NSString *s_user = nil;
static NSString *s_deviceId = nil;
static BOOL s_debugMode = NO;
static BOOL s_initialized = NO;
static BuglyLogLevel FoldCCBuglyLogLevel(int level)
{
switch (level)
{
case 1:
return BuglyLogLevelError;
case 2:
return BuglyLogLevelWarn;
case 3:
return BuglyLogLevelInfo;
case 4:
return BuglyLogLevelDebug;
default:
return BuglyLogLevelSilent;
}
}
#endif
extern "C"
{
void _BuglyInit(const char *appId, bool debug, int level)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
if (s_initialized)
{
return;
}
BuglyConfig *config = [[BuglyConfig alloc] init];
config.debugMode = debug;
config.reportLogLevel = FoldCCBuglyLogLevel(level);
config.channel = s_channel;
config.version = s_version;
config.deviceIdentifier = s_deviceId;
config.consolelogEnable = debug;
[Bugly startWithAppId:FoldCCBuglyString(appId) config:config];
if (s_user.length > 0)
{
[Bugly setUserIdentifier:s_user];
}
s_debugMode = debug;
s_initialized = YES;
#endif
}
void _BuglySetUserId(const char *userId)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
NSString *value = FoldCCBuglyString(userId);
s_user = [value copy];
if (s_initialized && value.length > 0)
{
[Bugly setUserIdentifier:value];
}
#endif
}
void _BuglySetTag(int tag)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
if (s_initialized)
{
[Bugly setTag:(NSUInteger)tag];
}
#endif
}
void _BuglySetKeyValue(const char *key, const char *value)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
NSString *keyString = FoldCCBuglyString(key);
if (s_initialized && keyString.length > 0)
{
[Bugly setUserValue:FoldCCBuglyString(value) forKey:keyString];
}
#endif
}
void _BuglyReportException(int type, const char *name, const char *reason, const char *stackTrace, const char *extras, bool quit)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
if (s_initialized)
{
[Bugly reportExceptionWithCategory:(NSUInteger)type
name:FoldCCBuglyString(name)
reason:FoldCCBuglyString(reason)
callStack:FoldCCBuglyStackFrames(FoldCCBuglyString(stackTrace))
extraInfo:FoldCCBuglyExtraInfo(FoldCCBuglyString(extras))
terminateApp:quit];
}
#endif
}
void _BuglyDefaultConfig(const char *channel, const char *version, const char *user, const char *deviceId)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
s_channel = [FoldCCBuglyString(channel) copy];
s_version = [FoldCCBuglyString(version) copy];
s_user = [FoldCCBuglyString(user) copy];
s_deviceId = [FoldCCBuglyString(deviceId) copy];
#endif
}
void _BuglyLogMessage(int level, const char *tag, const char *log)
{
#if FOLDCC_BUGLY_IOS_AVAILABLE
if (s_initialized)
{
[BuglyLog level:FoldCCBuglyLogLevel(level) tag:FoldCCBuglyString(tag) log:@"%@", FoldCCBuglyString(log)];
}
#endif
}
void _BuglyConfigCrashReporterType(int type)
{
}
void _BuglySetExtraConfig(const char *key, const char *value)
{
_BuglySetKeyValue(key, value);
}
}

View File

@@ -0,0 +1,34 @@
fileFormatVersion: 2
guid: 50f7f5117f28421589a4ea87b6824291
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
CompileFlags:
FrameworkDependencies:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,8 +2,8 @@
"name": "com.foldcc.cc-framework.crashreport", "name": "com.foldcc.cc-framework.crashreport",
"displayName": "CC-Framework.CrashReport", "displayName": "CC-Framework.CrashReport",
"description": "Crash检测 异常上报", "description": "Crash检测 异常上报",
"version": "1.0.1", "version": "1.0.2",
"unity": "2022.1", "unity": "2022.3",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -1,51 +1,60 @@
{ {
"dependencies": { "dependencies": {
"com.unity.2d.animation": { "com.unity.2d.animation": {
"version": "7.0.8", "version": "9.2.0",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.common": "6.0.5", "com.unity.2d.common": "8.1.0",
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.collections": "1.1.0",
"com.unity.modules.animation": "1.0.0", "com.unity.modules.animation": "1.0.0",
"com.unity.modules.uielements": "1.0.0" "com.unity.modules.uielements": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.2d.common": { "com.unity.2d.aseprite": {
"version": "6.0.5", "version": "1.1.9",
"depth": 2, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.common": "6.0.6",
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.mathematics": "1.1.0", "com.unity.mathematics": "1.2.6",
"com.unity.modules.uielements": "1.0.0", "com.unity.modules.animation": "1.0.0"
"com.unity.burst": "1.5.1"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.2d.path": { "com.unity.2d.common": {
"version": "5.0.2", "version": "8.1.0",
"depth": 2, "depth": 2,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {
"com.unity.burst": "1.7.3",
"com.unity.2d.sprite": "1.0.0",
"com.unity.mathematics": "1.1.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.uielements": "1.0.0"
},
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.2d.pixel-perfect": { "com.unity.2d.pixel-perfect": {
"version": "5.0.1", "version": "5.1.0",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.cn"
},
"com.unity.2d.psdimporter": {
"version": "6.0.6",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.animation": "7.0.8", "com.unity.modules.imgui": "1.0.0"
"com.unity.2d.common": "6.0.5", },
"com.unity.2d.sprite": "1.0.0" "url": "https://packages.unity.cn"
},
"com.unity.2d.psdimporter": {
"version": "8.1.0",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.2d.common": "8.1.0",
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.animation": "9.2.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
@@ -56,13 +65,12 @@
"dependencies": {} "dependencies": {}
}, },
"com.unity.2d.spriteshape": { "com.unity.2d.spriteshape": {
"version": "7.0.6", "version": "9.1.0",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.2d.common": "8.1.0",
"com.unity.mathematics": "1.1.0", "com.unity.mathematics": "1.1.0",
"com.unity.2d.common": "6.0.4",
"com.unity.2d.path": "5.0.2",
"com.unity.modules.physics2d": "1.0.0" "com.unity.modules.physics2d": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
@@ -71,26 +79,30 @@
"version": "1.0.0", "version": "1.0.0",
"depth": 1, "depth": 1,
"source": "builtin", "source": "builtin",
"dependencies": {} "dependencies": {
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.uielements": "1.0.0"
}
}, },
"com.unity.2d.tilemap.extras": { "com.unity.2d.tilemap.extras": {
"version": "2.2.3", "version": "3.1.3",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.modules.tilemap": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0" "com.unity.modules.jsonserialize": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.burst": { "com.unity.burst": {
"version": "1.6.6", "version": "1.8.21",
"depth": 3, "depth": 3,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.mathematics": "1.2.1" "com.unity.mathematics": "1.2.1",
"com.unity.modules.jsonserialize": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
@@ -103,6 +115,16 @@
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.collections": {
"version": "1.2.4",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.6.6",
"com.unity.test-framework": "1.1.31"
},
"url": "https://packages.unity.cn"
},
"com.unity.ext.nunit": { "com.unity.ext.nunit": {
"version": "1.0.6", "version": "1.0.6",
"depth": 1, "depth": 1,
@@ -115,13 +137,14 @@
"depth": 0, "depth": 0,
"source": "builtin", "source": "builtin",
"dependencies": { "dependencies": {
"com.unity.2d.animation": "7.0.8", "com.unity.2d.animation": "9.2.0",
"com.unity.2d.pixel-perfect": "5.0.1", "com.unity.2d.pixel-perfect": "5.1.0",
"com.unity.2d.psdimporter": "6.0.6", "com.unity.2d.psdimporter": "8.1.0",
"com.unity.2d.sprite": "1.0.0", "com.unity.2d.sprite": "1.0.0",
"com.unity.2d.spriteshape": "7.0.6", "com.unity.2d.spriteshape": "9.1.0",
"com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap": "1.0.0",
"com.unity.2d.tilemap.extras": "2.2.3" "com.unity.2d.tilemap.extras": "3.1.3",
"com.unity.2d.aseprite": "1.1.9"
} }
}, },
"com.unity.ide.rider": { "com.unity.ide.rider": {
@@ -164,19 +187,19 @@
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.nuget.newtonsoft-json": { "com.unity.nuget.newtonsoft-json": {
"version": "3.0.2", "version": "3.2.1",
"depth": 2, "depth": 2,
"source": "registry", "source": "registry",
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"com.unity.services.core": { "com.unity.services.core": {
"version": "1.6.0", "version": "1.14.0",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.0.2", "com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.modules.androidjni": "1.0.0" "com.unity.modules.androidjni": "1.0.0"
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
@@ -364,17 +387,6 @@
"version": "1.0.0", "version": "1.0.0",
"depth": 0, "depth": 0,
"source": "builtin", "source": "builtin",
"dependencies": {
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.uielementsnative": "1.0.0"
}
},
"com.unity.modules.uielementsnative": {
"version": "1.0.0",
"depth": 1,
"source": "builtin",
"dependencies": { "dependencies": {
"com.unity.modules.ui": "1.0.0", "com.unity.modules.ui": "1.0.0",
"com.unity.modules.imgui": "1.0.0", "com.unity.modules.imgui": "1.0.0",

View File

@@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.14f1c1 m_EditorVersion: 2022.3.62f3c1
m_EditorVersionWithRevision: 2021.3.14f1c1 (3aa525a93a5f) m_EditorVersionWithRevision: 2022.3.62f3c1 (1623fc0bbb97)