腾讯Bugly,为移动开发者提供专业的异常上报和运营统计,帮助开发者快速发现并解决异常,同时掌握产品运营动态,及时跟进用户反馈。
官方下载、文档介绍
使用
BuglyConfig *config = [[BuglyConfig alloc] init];
// 非正常退出事件记录开关
config.unexpectedTerminatingDetectionEnable = YES;
config.reportLogLevel = BuglyLogLevelWarn;
//开启卡顿监控,默认3s
config.blockMonitorEnable = YES;
config.delegate = self;
//config.blockMonitorTimeout = 1.5;
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *bundleShortVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *bundleVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
config.version = [NSString stringWithFormat:@"%@(%@)",bundleShortVersion,bundleVersion];
[Bugly startWithAppId:kBuglyApiKey
#ifndef DEBUG
developmentDevice:YES
#endif
config:config];
用户标识
//设置用户标识
[Bugly setUserIdentifier:***];
设置关键数据
//设置关键数据,随崩溃信息上报
[Bugly setUserValue:*** forKey:@"driverMobile"];
异常代理实现
返回需上报记录,随异常上报一起上报。
- (NSString * BLY_NULLABLE)attachmentForException:(NSException * BLY_NULLABLE)exception {
return @"***";
}
开启卡顿监控
//开启卡顿监控,默认3s
config.blockMonitorEnable = YES;
config.delegate = self;
//config.blockMonitorTimeout = 1.5;
日志上报
......
config.reportLogLevel = BuglyLogLevelWarn;
......
[BuglyLog log:@"test1"];
NSArray *array = @[];
[array objectAtIndex:2];
[BuglyLog log:@"test2"];
reportLogLevel是一个枚举类型属性,BuglyLogLevelWarn及BuglyLogLevelInfo都可进行日志上报,区别在于BuglyLogLevelWarn日志相对清晰,BuglyLogLevelInfo可以将自定义的打印日志上报。
DSYM 文件上报
#!/bin/sh
# Copyright 2014-2015 Bugly @Tencent. All rights reserved.
#
################################################################################
# 注意: 请配置下面的信息
################################################################################
BUGLY_APP_ID=""
BUGLY_APP_KEY=""
ENABEL_BUGLY_SYMBOL_UPLOAD=1 #Archive是否开启符号上传(个别机器没有java环境可以设置0)
################################################################################
# 自定义配置
################################################################################
# Debug模式编译是否上传,1=上传 0=不上传,默认不上传
UPLOAD_DEBUG_SYMBOLS=1
#
# 模拟器编译是否上传,1=上传 0=不上传,默认不上传
UPLOAD_SIMULATOR_SYMBOLS=0
#
# # 脚本默认配置的版本格式为CFBundleShortVersionString(CFBundleVersion), 如果你修改默认的版本格式, 请设置此变量, 如果不想修改, 请忽略此设置
# CUSTOMIZED_APP_VERSION=""
#
#
#
# This script will extract symbols from the .dSYM and generate .symbol file(Bugly supported) and upload to server.
# You could visit http://bugly.qq.com to get more details about Bugly.
#
# Usage:
# * The instructions assume you have copyed this script into your project int Xcode.
# * Copy the "buglySymbolIOS.jar" file into the "~/bin" folder.
# * Open the project editor, select your build target.
# * Click "Build Phases" at the top of the project editor.
# * Click "+" button in the top left corner and select "New Run Script Phase".
# * Click "Run Script".
# * Paste the following script into the dark text box. You will have to uncomment the lines (remove the #) of course.
#
# --- SCRIPT BEGINS ON NEXT LINE, COPY AND EDIT FROM THERE ---
#
#
#
# --- END OF SCRIPT ---
################################################################################
# 注意: 如果你不知道此脚本的执行流程和用法,请不要随便修改!
################################################################################
# 退出执行并打印提示信息
exitWithMessage() {
echo "--------------------------------"
echo -e "${1}"
echo "--------------------------------"
echo "No upload and exit."
echo "----------------------------------------------------------------"
exit ${2}
}
# 上传
function upload() {
echo "---------------开始上传-----------------"
for dsymFile in $(find "$DSYM_FOLDER" -name '*.dSYM'); do
echo "正在上传: $dsymFile"
(/usr/bin/java -jar "${BUGLY_SYMBOL_JAR_PATH}" -appid "${BUGLY_APP_ID}" -appkey "${BUGLY_APP_KEY}" -bundleid "${BUNDLE_IDENTIFIER}" -version "${BUNDLE_SHORT_VERSION}.${BUNDLE_VERSION}" -platform "IOS" -inputSymbol ${dsymFile} ) || exitWithMessage "Error: Failed to extract symbols." 1
done
echo "---------------上传完成-----------------"
}
echo "----------------------------------------------------------------"
echo "Copyright 2014-2015 Bugly @Tencent. All rights reserved."
echo "This script will extract symbols from the .dSYM file and generate .symbol file(Bugly supported) and upload to server."
echo "You could visit http://bugly.qq.com to get more details about Bugly."
echo "----------------------------------------------------------------"
echo "Uploading dSYM to Bugly."
echo ""
##plist路径
TEMP_APP_INFO_PLIST=$1
#jar路径 去bugly下载jar包,确保电脑有该java环境
BUGLY_SYMBOL_JAR_PATH=$2
#DSYM文件所在文件夹
DSYM_FOLDER=$3
if [ -n "$TEMP_APP_INFO_PLIST" ]; then
echo "TEMP_APP_INFO_PLIST==$TEMP_APP_INFO_PLIST"
else
echo "plist路径"
# 读取输入
read plist
sleep 0.1
TEMP_APP_INFO_PLIST="$plist"
echo "TEMP_APP_INFO_PLIST==$TEMP_APP_INFO_PLIST"
fi
if [ -n "$BUGLY_SYMBOL_JAR_PATH" ]; then
echo "BUGLY_SYMBOL_JAR_PATH==$BUGLY_SYMBOL_JAR_PATH"
else
echo "jir路径"
# 读取输入
read jir
sleep 0.1
BUGLY_SYMBOL_JAR_PATH="$jir"
echo "BUGLY_SYMBOL_JAR_PATH==$BUGLY_SYMBOL_JAR_PATH"
fi
if [ -n "$DSYM_FOLDER" ]; then
echo "DSYM_FOLDER==$DSYM_FOLDER"
else
echo "DSYM文件夹"
# 读取输入
read dsym
sleep 0.1
DSYM_FOLDER="$dsym"
echo "DSYM_FOLDER==$DSYM_FOLDER"
fi
# 获取app的名称、版本号、build号
PRODUCT_NAME=`/usr/libexec/PlistBuddy -c "Print :CFBundleDisplayName" $TEMP_APP_INFO_PLIST`
BUNDLE_SHORT_VERSION=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" $TEMP_APP_INFO_PLIST`
BUNDLE_VERSION=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" $TEMP_APP_INFO_PLIST`
BUNDLE_IDENTIFIER=`/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" $TEMP_APP_INFO_PLIST`
echo "--------------------------------"
echo "Step 1: Prepare application information."
echo "--------------------------------"
echo "Product Name: ${PRODUCT_NAME}"
echo "Bundle Identifier: ${BUNDLE_IDENTIFIER}"
echo "Version: ${BUNDLE_SHORT_VERSION}"
echo "Build: ${BUNDLE_VERSION}"
echo "Bugly App ID: ${BUGLY_APP_ID}"
echo "Bugly App key: ${BUGLY_APP_KEY}"
echo "--------------------------------"
echo "Step 2: Check the arguments ..."
# 是否开启上传功能
if [ $ENABEL_BUGLY_SYMBOL_UPLOAD -eq 0 ]; then
exitWithMessage "已关闭bugly符号上传.(如有需要开启请设置ENABEL_BUGLY_SYMBOL_UPLOAD=1)" 0
fi
# 检查模拟器编译是否允许上传符号
if [ "$EFFECTIVE_PLATFORM_NAME" == "-iphonesimulator" ]; then
if [ $UPLOAD_SIMULATOR_SYMBOLS -eq 0 ]; then
exitWithMessage "Warning: Build for simulator and skipping to upload. \nYou can modify 'UPLOAD_SIMULATOR_SYMBOLS' to 1 in the script." 0
fi
fi
if [ "${CONFIGURATION=}" == "Debug" ]; then
if [ $UPLOAD_DEBUG_SYMBOLS -eq 0 ]; then
exitWithMessage "Warning: Build for debug mode and skipping to upload. \nYou can modify 'UPLOAD_DEBUG_SYMBOLS' to 1 in the script." 0
fi
fi
# 检查必须参数是否设置
if [ ! "${BUGLY_APP_ID}" ]; then
exitWithMessage "Error: Bugly App ID not defined." 1
fi
if [ ! "${BUGLY_APP_KEY}" ]; then
exitWithMessage "Error: Bugly APP Key not defined." 1
fi
if [ ! "${BUNDLE_IDENTIFIER}" ]; then
exitWithMessage "Error: Bundle Identifier not defined." 1
fi
##检查是否Archive操作
#if [[ "$TARGET_BUILD_DIR" == *"/Archive"* ]]; then
# echo "Archive the package"
#else
# exitWithMessage "Warning: Build for NOT Archive mode and skipping to upload." 0
#fi
# 提取符号信息
echo "--------------------------------"
echo "Step 3: Extract symbol info from .dSYM file."
if [ ! -e "$BUGLY_SYMBOL_JAR_PATH" ]; then
exitWithMessage "Error: Jar file '${BUGLY_SYMBOL_JAR_PATH}' was not found. \nPlease copy the jar file into ~/bin folder." 1
fi
# 上传
upload
exit 0
目前只支持Java8环境上传。
解决
编辑 .bash_profile,添加 JAVA_HOME:
# JDK 8
export JAVA_HOME_8=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export JAVA_HOME_19=/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
alias jdk8="export JAVA_HOME=$JAVA_HOME_8"
alias jdk19="export JAVA_HOME=$JAVA_HOME_19"
export PATH=$PATH:$JAVA_HOME_19
刷新配置:
source ~/.bash_profile
或者如果是 zsh
source ~/.zshrc
切换版本
~ % jdk8
~ % java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)