React Native集成Sentry之手动安装(IOS)

单于智
2023-12-01

如果您不能(或不想)运行链接步骤,您可以在此处看到每个平台上发生的情况。

iOS

1、AppDelegate

#if __has_include(<React/RNSentry.h>)
#import <React/RNSentry.h> // This is used for versions of react >= 0.40
#else
#import "RNSentry.h" // This is used for versions of react < 0.40
#endif

/* in your didFinishLaunchingWithOptions */
[RNSentry installWithRootView:rootView];

2、构建步骤

使用Xcode时,您可以直接挂钩到构建过程以上载调试符号。链接时,会更改一个构建阶段脚本,并添加另外两个脚本。

我们稍微修改了react-native构建阶段(“Bundle React Native code and images”):

export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh

对此:

export NODE_BINARY=node
export SENTRY_PROPERTIES=sentry.properties

# If you are using RN 0.46+
../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \
  ../node_modules/react-native/scripts/react-native-xcode.sh

# For RN < 0.46
../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \
  ../node_modules/react-native/packager/react-native-xcode.sh

 另外,我们添加了一个名为“将调试符号上传到Sentry”的构建脚本,该脚本将调试符号上传到Sentry。

但是,这对于启用bitcode的构建不起作用。如果你正在使用bitcode,你需要删除该行(sentry-cli upload-dsym)并参考dsym处理的文档(参见With Bitcode)。

请注意,出于速度原因,默认情况下禁用上载调试模拟器构建。如果您还希望为调试版本生成调试符号,则可以在上述构建阶段将--allow-fetch作为参数传递给react-native-xcode。

3、使用nvm节点

如果您使用的是nvm,Xcode似乎在查找默认节点二进制文件时遇到问题。在这种情况下,您应该将脚本更改为:

# First set the path to sentry.properties
export SENTRY_PROPERTIES=sentry.properties

# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
eval "$("$HOME/.nodenv/bin/nodenv" init -)"
fi

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

# Run sentry cli script to upload debug symbols
$NODE_BINARY ../node_modules/@sentry/cli/bin/sentry-cli upload-dsym

# OR

$NODE_BINARY ../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \
  ../node_modules/react-native/scripts/react-native-xcode.sh

 

 类似资料: