应用场景:Android+IOS 客户端收集异常反馈数据,方便维护。
1:登陆Bugly官网,注册账号并“新建产品”,可以获取到一个“APP ID”,之后有用。
2:下载插件:https://bugly.qq.com/v2/downloads,并导入项目中,注意插件中并未包含IOS的相关插件
将:BuglyBridge/ios/BuglyBridge 文件夹拖到项目Plugins/IOS中,BuglySDK/IOS/Bugly.framework拖到
项目assest目录中
3:Unity中添加Bugly初始化代码:初始代码就这么简单,简单的添加一些测试代码
private void initBugly()
{
BuglyAgent.ConfigDebugMode(true);
#if UNITY_IPHONE||UNITY_IOS
BuglyAgent.InitWithAppId("你的APPID");
#elif UNITY_ANDROID
BuglyAgent.InitWithAppId("你的APPID");
#endif
BuglyAgent.EnableExceptionHandler();
}
private void OnGUI()
{
if(GUI.Button(new Rect(100,100,100,50),"数组超范围")){
byte[] byteArr = new byte[20];
byteArr[21] = 0x11;
}
if(GUI.Button(new Rect(100,200,100,50),"Null")){
GameObject obj = null;
obj.transform.SetParent(this.transform);
}
}
4:打包Xcode工程:
添加相关依赖包:
- libz.dylib - 用于对上报数据进行压缩
- Security.framework - 用于存储keychain
- SystemConfiguration.framework - 用于读取异常发生时的系统信息
- JavaScriptCore.framework - 设置为Optional
- libc++.dylib - libc++库依赖
5:填坑
(1)Not found class 'Bugly',解决方法:删除并重新添加Bugly.framework依赖就可以
[BuglyAgent] <Debug> - : Enable the log message print to console
2018-06-06 15:45:56.908010+0800 gps[5156:2416485] <Error> BuglyAgentV2: Not found class 'Bugly'
[BuglyAgent] <Debug> - : Initialized with app id: e8429856ea
[BuglyAgent] <Debug> - : Register the log callback in Unity 5.6.4f1
[BuglyAgent] <Debug> - : BuglyAgent has already been initialized.
Setting up 1 worker threads for Enlighten.
Thread -> id: 16ed8f000 -> priority: 1