xcode - 在 React Native 应用程序中为 Fabric crashlytics 日志添加导入文件后,在 Xcode 中找不到 RCTLog.h 文件错误

标签 xcode react-native error-handling crashlytics google-fabric

我在我的 React native 应用程序中安装了带有 crashlytics 的 Fabric。有时即使您的应用程序中有此设置,捕获错误也是一个大问题,因为当您的应用程序崩溃时,crashlytics 不会向您显示有关错误的全部信息。因此,我决定将日志从 JS 线程设置到 Fabric,根据这篇文章 https://medium.com/delivery-com-engineering/add-crashlytics-to-your-react-native-ios-app-69a983a9062a .我得到了这个错误 'RCTLog.h' 文件未找到 将这行代码添加到我的 AppDelegate.m 之后:

#import <asl.h>
#import "RCTLog.h"

我在 SWIFT 方面的能力并不强。你能告诉我在哪里可以找到这些文件,或者给我一个例子,我该如何创建它。

最佳答案

我找到了决定。我已经创建了 RCTLog.h 文件,它是一个头文件,在与 AppDelegate.m 相同的目录中。
RCTLog.h:

/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import <Foundation/Foundation.h>

#import <React/RCTAssert.h>
#import <React/RCTDefines.h>
#import <React/RCTUtils.h>

#ifndef RCTLOG_ENABLED
#define RCTLOG_ENABLED 1
#endif

/**
 * Thresholds for logs to display a redbox. You can override these values when debugging
 * in order to tweak the default logging behavior.
 */
#ifndef RCTLOG_REDBOX_LEVEL
#define RCTLOG_REDBOX_LEVEL RCTLogLevelError
#endif

/**
 * Logging macros. Use these to log information, warnings and errors in your
 * own code.
 */
#define RCTLog(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogTrace(...) _RCTLog(RCTLogLevelTrace, __VA_ARGS__)
#define RCTLogInfo(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogAdvice(string, ...) RCTLogWarn([@"(ADVICE) " stringByAppendingString:(NSString *)string], __VA_ARGS__)
#define RCTLogWarn(...) _RCTLog(RCTLogLevelWarning, __VA_ARGS__)
#define RCTLogError(...) _RCTLog(RCTLogLevelError, __VA_ARGS__)

/**
 * An enum representing the severity of the log message.
 */
typedef NS_ENUM(NSInteger, RCTLogLevel) {
  RCTLogLevelTrace = 0,
  RCTLogLevelInfo = 1,
  RCTLogLevelWarning = 2,
  RCTLogLevelError = 3,
  RCTLogLevelFatal = 4
};

/**
 * An enum representing the source of a log message.
 */
typedef NS_ENUM(NSInteger, RCTLogSource) {
  RCTLogSourceNative = 1,
  RCTLogSourceJavaScript = 2
};

/**
 * A block signature to be used for custom logging functions. In most cases you
 * will want to pass these arguments to the RCTFormatLog function in order to
 * generate a string.
 */
typedef void (^RCTLogFunction)(
  RCTLogLevel level,
  RCTLogSource source,
  NSString *fileName,
  NSNumber *lineNumber,
  NSString *message
);

/**
 * A method to generate a string from a collection of log data. To omit any
 * particular data from the log, just pass nil or zero for the argument.
 */
RCT_EXTERN NSString *RCTFormatLog(
  NSDate *timestamp,
  RCTLogLevel level,
  NSString *fileName,
  NSNumber *lineNumber,
  NSString *message
);

/**
 * A method to generate a string RCTLogLevel
 */
RCT_EXTERN NSString *RCTFormatLogLevel(RCTLogLevel);

/**
 * A method to generate a string from a RCTLogSource
 */
RCT_EXTERN NSString *RCTFormatLogSource(RCTLogSource);

/**
 * The default logging function used by RCTLogXX.
 */
extern RCTLogFunction RCTDefaultLogFunction;

/**
 * These methods get and set the global logging threshold. This is the level
 * below which logs will be ignored. Default is RCTLogLevelInfo for debug and
 * RCTLogLevelError for production.
 */
RCT_EXTERN void RCTSetLogThreshold(RCTLogLevel threshold);
RCT_EXTERN RCTLogLevel RCTGetLogThreshold(void);

/**
 * These methods get and set the global logging function called by the RCTLogXX
 * macros. You can use these to replace the standard behavior with custom log
 * functionality.
 */
RCT_EXTERN void RCTSetLogFunction(RCTLogFunction logFunction);
RCT_EXTERN RCTLogFunction RCTGetLogFunction(void);

/**
 * This appends additional code to the existing log function, without replacing
 * the existing functionality. Useful if you just want to forward logs to an
 * extra service without changing the default behavior.
 */
RCT_EXTERN void RCTAddLogFunction(RCTLogFunction logFunction);

/**
 * This method temporarily overrides the log function while performing the
 * specified block. This is useful for testing purposes (to detect if a given
 * function logs something) or to suppress or override logging temporarily.
 */
RCT_EXTERN void RCTPerformBlockWithLogFunction(void (^block)(void), RCTLogFunction logFunction);

/**
 * This method adds a conditional prefix to any messages logged within the scope
 * of the passed block. This is useful for adding additional context to log
 * messages. The block will be performed synchronously on the current thread.
 */
RCT_EXTERN void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix);

/**
 * Private logging function - ignore this.
 */
#if RCTLOG_ENABLED
#define _RCTLog(lvl, ...) _RCTLogNativeInternal(lvl, __FILE__, __LINE__, __VA_ARGS__)
#else
#define _RCTLog(lvl, ...) do { } while (0)
#endif

RCT_EXTERN void _RCTLogNativeInternal(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);
RCT_EXTERN void _RCTLogJavaScriptInternal(RCTLogLevel, NSString *);

关于xcode - 在 React Native 应用程序中为 Fabric crashlytics 日志添加导入文件后,在 Xcode 中找不到 RCTLog.h 文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60037433/

相关文章:

haskell - 如何使用 exceptT 替换大量 IO(a b)

python - 无法诊断无效的语法错误(Python)

xcode - 在哪里可以获得 XCode 的 10.6 SDK

ios - NSDateFormatter dateFromString 返回错误月份的日期

ios - Sprite Kit 的 'didBeginContact' 函数不是很准确。我应该怎么办?

javascript - 使用 react-native-modal-dropdown 时获取选择的值

javascript - 为什么当 redux 状态改变时 props.screenProps 会变成 undefined

ios - 在哪里管理 Xcode 4 中的构建配置?

react-native - 在 React Native 中导入 yaml 文件导致数字 1 而不是实际内容

java - Tomcat 为带空格的请求 URI 返回 505