在 SPM 中导入 .framework(Swift 包管理器)

import .framework inside SPM (Swift Package Manager)

我们正在尝试将 TikTokOpenSDK.frameoworkhttps://developers.tiktok.com/doc/ios_quickstart)整合到我们的自定义 Swift Package

TikTok 只给我们.framework 访问权限(您可以手动下载)。到目前为止,我没有整合它,无论我尝试什么组合,它都会失败 unsupported extension for binary target ‘TikTokOpenSDK’; valid extensions are: xcframework:

我们将不胜感激任何帮助。谢谢!

Swift 包管理器仅支持 XCFrameworks。您唯一的选择是将经典框架转换为 XCFramework。我 done this in the past for the SendbirdSDK and everything worked out okay (though I can't give a full guarantee this will work for TikTok!). The gist of the process is that you want to create the XCFramework structure as described here。请注意,这是逆向工程,因此可能会发生变化。

如果你想让切片尽可能紧凑,这将涉及很多文件夹,但如果你根本不关心并且只需要它 运行 在模拟器和 iOS 设备遵循树的工作原理:

TikTokOpenSDK.xcframework
- Info.plist
- universal-simulator
    - TikTokOpenSDK.framework
- universal-hardware
    - TikTokOpenSDK.framework

然后前面提到的Info.plist应该包含:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>LibraryIdentifier</key>
        <string>universal-simulator</string>
        <key>LibraryPath</key>
        <string>TikTokOpenSDK.framework</string>
        <key>SupportedArchitectures</key>
        <array>
            <string>arm64</string>
            <string>x86_64</string>
        </array>
        <key>SupportedPlatform</key>
        <string>ios</string>
        <key>SupportedPlatformVariant</key>
        <string>simulator</string>
    </dict>
    <dict>
        <key>LibraryIdentifier</key>
        <string>universal-hardware</string>
        <key>LibraryPath</key>
        <string>TikTokOpenSDK.framework</string>
        <key>SupportedArchitectures</key>
        <array>
            <string>arm64</string>
            <string>armv7k</string>
        </array>
        <key>SupportedPlatform</key>
        <string>ios</string>
    </dict>
</array>
</plist>

创建此结构(并直接放入原始框架)后,您应该能够将此 XCFramework 包含在 SPM 中,它应该会按预期工作!