使用Reveal11调试ios项目

前言:RevealUI界面工具可以在不重新编译的情况下,实时调试ios项目的UI界面,这对于开发者可以提供不少的方便。我在使用过程中也遇到了一些问题,查询了网上的一些资料发现好多都是老的了,大多都是针对reveal2和reveal8的文章,有的是需要libReveal.dylib文件的,而reveal11已经没有libReveal.dylib这个文件了,最后在官方论坛找了一个使用教程才解决了我的问题,以下内容主要是对该文章的翻译和修改。图片有原文中的原图,也有我自己的截图,仅供参考

原文: Integrating Reveal via Linking

操作环境

macOS : 10.13.1
Xcode : 9.1

Podfile示例

# Uncomment the next line to define a global platform for your project
# platform :ios, '11.0'

def pods
  pod 'Reveal-SDK', :configurations => ['Debug']
end

target 'SwiftStudy' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  pods

  # Pods for SwiftStudy

  target 'SwiftStudyTests' do
    inherit! :search_paths
    # Pods for testing
    pods
  end

  target 'SwiftStudyUITests' do
    inherit! :search_paths
    # Pods for testing
    pods
  end

end

操作步骤

  1. 启动Reveal应用并且选择 “help->Show Reveal Library in Finder”,在打开的目录里选中RevealServer.framework,然后根据应用类别选择IOS Library 还是tvOS Library
    show-reveal-library-in-finder.jpg

  2. 按住“Option(⌥)”键,将RevealServer.framework拖拽到项目中,该步骤会复制RevealServer.framework到项目中,可以是根路径也可以是其它路径,看你拖拽到哪里了。

    注意:为了确保是复制到项目目录,请一定要按住option键。

复制RevealServer.framework到项目根路径

  1. 用Xcode打开项目,选择项目图标,打开Xcode项目导航

  2. 在左侧的target列表中选择一个你想调试的target

  3. 选择Build Settings 标签,在“Framework Search Paths(框架搜索路径)”中的Debug设置中增加

  $(inherited) $(SRCROOT)

add_framework_search_paths.jpg

  1. 还是在Build Settings 标签,在“Other Linker Flags”的Debug配置中添加
  -ObjC -weak_framework RevealServer

因为我是用pod自动安装的reveal,所以操作该步时,该配置我已经有了。

  1. 仍然在Build Settings 标签,
    在“ Runpath Search Paths ”的Debug配置中添加“$(inherited) @executable_path/Frameworks”,若已有则不操作。

  2. 选择“Build Phases”标签,添加一个新的脚本,命名为“Integrate Reveal Server”或者其它合适的名字,粘贴下面的代码。

  export REVEAL_SERVER_FILENAME="RevealServer.framework"

  # Update this path to point to the location of RevealServer.framework in your project.
export REVEAL_SERVER_PATH="${SRCROOT}/${REVEAL_SERVER_FILENAME}"

  # If configuration is not Debug, skip this script.
[ "${CONFIGURATION}" != "Debug" ] && exit 0

  # If RevealServer.framework exists at the specified path, run code signing script.
if [ -d "${REVEAL_SERVER_PATH}" ]; then
  "${REVEAL_SERVER_PATH}/Scripts/copy_and_codesign_revealserver.sh"
else
  echo "Cannot find RevealServer.framework, so Reveal Server will not be started for your app."
  fi

提醒:如果你将RevealServer.framework放置在了非根路径的其它地方了,就修改下REVEAL_SERVER_PATH的赋值。

添加一个新的脚本

  1. 编译运行项目,如果是用真机测试,请确保mac和你的设置同处在同一局域网中,或者你的设置正在通过use或者type-c等接口连接。

  2. 此时,在Reveal中会看到正在调试的App,双击打开即可开始进行UI界面调试。

不需要添加任何额外的代码或者其它什么引用,当你的应用进行调试时,Reveal框架会自动载入并开始提供必要的Reveal服务。

添加新评论