1. 高级功能

1.1. 自定义日志

SDK提供自定义日志接口,用户可用于记录一些关键的调试信息,用于分析crash或自定义错误发生时的上下文环境。

    RifleConfig *config = [RifleConfig new];

    //设置自定义日志的上报级别,默认不上报
    [Rifle setLogLevel:RifleLogLevelInfo consolePrint:NO];

    [Rifle startWithAppId:@"app-id" config:config];

自定义日志接口如下:

RFLogDebug(fmt, ...)

RFLogInfo(fmt, ...)  

RFLogWarning(fmt, ...)  

RFLogError(fmt, ...)

1.2. 接口声明

1.2.1. 配置接口

/**
 *  设置自定义渠道标识
 */
@property (nonatomic, copy) NSString *channel;

/**
 *  设置自定义设备唯一标识
 */
@property (nonatomic, copy) NSString *deviceId;

/**
 *  设置自定义版本号,如果不设置则按下面规则来取:"CFBundleShortVersionString (CFBundleVersion)"
 */
@property (nonatomic, copy) NSString *customAppVersion;

/**
 *  Rifle Delegate
 */
@property (nonatomic, assign) id delegate;

1.2.2. 功能接口

/**
 *  初始化Rifle,使用默认RifleConfig
 *
 *  @param appId 注册Rifle分配的应用唯一标识
 */
//+ (void)startWithAppId:(NSString * RIFLE_NULLABLE)appId;

/**
 *  使用指定配置初始化Rifle
 *
 *  @param appId 注册Rifle分配的应用唯一标识
 *  @param config 传入配置的 RifleConfig
 */
+ (void)startWithAppId:(NSString *)appId
                config:(RifleConfig * RIFLE_NULLABLE)config;

/**
 *  设置用户标识
 *
 *  @param userId 用户标识
 */
+ (void)setUserIdentifier:(NSString *)userId;

/**
 *  设置关键数据,随崩溃信息上报
 *
 *  @param value KEY
 *  @param key VALUE
 */
+ (void)setUserValue:(NSString *)value
              forKey:(NSString *)key;

/**
 *  获取关键数据
 *
 *  @return 关键数据
 */
+ (NSDictionary * RIFLE_NULLABLE)allUserValues;

/**
 *  获取设备ID
 *
 *  @return 设备ID
 */
+ (NSString *)RifleDeviceId;

/**
 *  SDK 版本信息
 *
 *  @return SDK版本号
 */
+ (NSString *)sdkVersion;

/**
 *  SDK 版本信息
 *
 *  @return SDK版本号
 */
+ (NSUInteger)sdkVersionNumber;

/**
 *  设置Log的等级,是否在控制台打印日志
 *
 *  @param level              log等级,默认为RifleLogLevelSilent
 *  @param consolePrint       是否在控制台打印日志,默认为 NO
 */
+ (void)setLogLevel:(RifleLogLevel)level consolePrint:(BOOL)consolePrint;

1.2.3. 自定义异常

SDK支持上报自定义异常,后台会对异常进行分类展示。


typedef NS_ENUM(NSUInteger, RifleExceptionType) {
    RifleExceptionType_Cocoa = 1,
    RifleExceptionType_CSharp = 2,
    RifleExceptionType_JS = 3,
    RifleExceptionType_Lua = 4,
    RifleExceptionType_Custom = 5
};


/**
 *    @brief 上报自定义异常
 *
 *    @param category    RifleExceptionType类型,支持Cocoa/CSharp/JS/Lua/Custom
 *    @param aName       名称
 *    @param aReason     错误原因
 *    @param aStackArray 堆栈
 *    @param info        附加数据
 */
+ (void)reportExceptionWithCategory:(RifleExceptionType)category
                               name:(NSString *)aName
                             reason:(NSString *)aReason
                          callStack:(NSArray * RIFLE_NULLABLE)aStackArray
                          extraInfo:(NSDictionary * RIFLE_NULLABLE)info;

1.3. 接收上传符号表日志

当使用自动上传符号表功能时,如果想要第一时间看到符号表是否上传成功,可以使用邮箱接收上传符号表日志。 脚本配置如下:

其中,RIFLE_EMAIL_STRING 中需要配置sendEmail的参数,其中:

-f your-mail@163.com // 配置发送者
-t your-mail@163.com // 配置接收者
-s smtp.163.com // 配置smtp server
-xu user-name // 配置发送邮箱的用户名
-xp user-password // 配置发送邮箱的密码
-u \" [Rifle上传符号表日志] $Bundle_Name $Bundle_Version($Bundle_Build_Number)\" // 配置邮件标题

⚠️:不需要配置邮件正文,应用程序会自动填充日志到邮件正文。 更多关于sendEmail的信息可以点击这里

####################################################################
#       请注意配置app-id 和 app-key
####################################################################
RIFLE_APP_ID="app-id"
RIFLE_APP_KEY="app-key"

####################################################################
#       符号表默认只在非DEBUG下上传,如果想在DEBUG下上上传
#       打开 RIFLE_FORCE_UPLOAD
#       如果想要使用邮箱接收上传符号表日志,需要
#       打开 RIFLE_SEND_EMAIL,另外需要配置 RIFLE_EMAIL_STRING
####################################################################
INFOPATH="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
Bundle_Name=`defaults read $INFOPATH CFBundleName`
Bundle_Version=`defaults read $INFOPATH CFBundleShortVersionString`
Bundle_Build_Number=`defaults read $INFOPATH CFBundleVersion`

#export RIFLE_FORCE_UPLOAD="EN" 
#export RIFLE_SEND_EMAIL="EN"
#export RIFLE_EMAIL_STRING="-o tls=no -o message-content-type=text -o message-charset=utf-8 -f your-mail@163.com -t your-mail@163.com -s smtp.163.com -xu user-name -xp user-password -u \" [Rifle上传符号表日志] $Bundle_Name $Bundle_Version($Bundle_Build_Number)\"" 

####################################################################
#       下面脚本会在构建阶段自动异步上传符号表,注意不要写错脚本地址
####################################################################
./TestRifle/Rifle/Rifle.framework/run ${RIFLE_APP_ID} ${RIFLE_APP_KEY
#}
# ./Pods/Rifle/iOS/Rifle.framework/run ${RIFLE_APP_ID} ${RIFLE_APP_KEY} # 如果使用cocoapods 
Copyright © momo 2019 all right reserved,powered by Gitbook修订时间: 2019-05-16 15:36:00

results matching ""

    No results matching ""