将iOS框架作为文件或Pod分发 [英] Distributing iOS framework as file or pods

查看:56
本文介绍了将iOS框架作为文件或Pod分发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从必须在产品中使用的客户端中添加一个框架,该框架以文件形式分发.

I try to add a framework from a client that we have to use in our product, and it is distributed as a file.

我面临的问题是该框架无法与模拟器一起使用,当我想使用模拟器时,必须使用框架的调试版本.但是当我们发布到应用商店时,无法包含调试版本,他们会拒绝使用该版本.

The problem I am facing is that the framework does not work with the simulator, I have to use a debug version of the framework when I want to use the simulator. But the debug version can not be included when we release to app store, it will be rejected they say.

当我用Google搜索这个问题时,苹果似乎不允许这种框架.还是最近改变了?

When I google this problem, it looks like Apple does not allow this kind of frameworks. Or has this been changed lately?

我还找到有关所谓FAT框架的信息,这是新东西吗?

I also find information about so called FAT frameworks, is that something new?

我试图在apple.com上找到有关此信息,但是我没有找到任何可以解释这种情况的信息.

I have tried to find information about this on apple.com, but I haven't found anything that explains the situation.

当我使用像Firebase这样的作为pod分发的框架时,我没有这个问题.

When I use a framework like Firebase that is distributed as pod I don't have this problem.

这些框架之间有什么区别? 客户端可以使用该框架吗,以便可以在模拟器和应用商店中使用它?

What is the difference between these frameworks? Is it something that the client can do with the framework so that it is possible to use it both in simulator and in app store?

推荐答案

当我用Google搜索这个问题时,苹果似乎不允许这种框架.还是最近改变了?

When I google this problem, it looks like Apple does not allow this kind of frameworks. Or has this been changed lately?

它的工作方式是Apple不允许将模拟器二进制文件(x86_64和i386)上传到应用商店.

The way it works is that Apple doesn't allow simulator binaries (x86_64 and i386) to be uploaded to the app store.

我还找到有关所谓FAT框架的信息,这是新事物吗?

I also find information about so called FAT frameworks, is that something new?

FAT框架并不是什么新鲜事物.它们基本上是FAT二进制文件的包装器. FAT二进制文件包含多种体系结构.

FAT frameworks are nothing new. They are basically a wrapper around a FAT binary. A FAT binary contains multiple architectures.

当我使用像Firebase这样的作为pod分发的框架时,我没有这个问题.

When I use a framework like Firebase that is distributed as pod I don't have this problem.

它们没有此问题,因为它们以Pod的形式分发.这些框架具有FAT二进制文件,即同时包含Device(armv7,arm64)和Simulator(i386,x86_64).然后真正的魔力发生在可可足的尽头. Cocoapods使用构建时间脚本来剥离不必要的体系结构的二进制文件.

They don't have this problem because they are distributed as Pods. These frameworks have FAT binaries, i.e. containing both Device (armv7, arm64) and Simulator (i386, x86_64). And then the real magic happens at Cocoapods' end. Cocoapods uses a build time script to strip the binary of unnecessary architectures.

您可以通过使用cocoapods使用的脚本来对您的框架进行相同的操作:)

You can do the same with your framework by using the same script that cocoapods uses :)

#!/bin/sh
set -e

echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"

SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"

install_framework()
{
  if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$1"
  elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
  elif [ -r "$1" ]; then
    local source="$1"
  fi

  local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"

  if [ -L "${source}" ]; then
      echo "Symlinked..."
      source="$(readlink "${source}")"
  fi

  # use filter instead of exclude so missing patterns dont' throw errors
  echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
  rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"

  local basename
  basename="$(basename -s .framework "$1")"
  binary="${destination}/${basename}.framework/${basename}"
  if ! [ -r "$binary" ]; then
    binary="${destination}/${basename}"
  fi

  # Strip invalid architectures so "fat" simulator / device frameworks work on device
  if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
    strip_invalid_archs "$binary"
  fi

  # Resign the code if required by the build settings to avoid unstable apps
  code_sign_if_enabled "${destination}/$(basename "$1")"

  # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
  if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
    local swift_runtime_libs
    swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u  && exit ${PIPESTATUS[0]})
    for lib in $swift_runtime_libs; do
      echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
      rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
      code_sign_if_enabled "${destination}/${lib}"
    done
  fi
}

# Signs a framework with the provided identity
code_sign_if_enabled() {
  if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
    # Use the current code_sign_identitiy
    echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
    local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '$1'"

    if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
      code_sign_cmd="$code_sign_cmd &"
    fi
    echo "$code_sign_cmd"
    eval "$code_sign_cmd"
  fi
}

# Strip invalid architectures
strip_invalid_archs() {
  binary="$1"
  # Get architectures for current file
  archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
  stripped=""
  for arch in $archs; do
    if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
      # Strip non-valid architectures in-place
      lipo -remove "$arch" -output "$binary" "$binary" || exit 1
      stripped="$stripped $arch"
    fi
  done
  if [[ "$stripped" ]]; then
    echo "Stripped $binary of architectures:$stripped"
  fi
}

只需将您的框架传递给install_framework方法,如下所示:

Just pass your framework to install_framework method like so:

install_framework "$BUILT_PRODUCTS_DIR/BadgeSwift/BadgeSwift.framework"

这篇关于将iOS框架作为文件或Pod分发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆