配置 Broadcast Upload Extension,以便在 RealtimeKit iOS 应用中添加屏幕共享。
在 Xcode 中,通过 File → New → Target 添加 Broadcast Upload Extension。选择 iOS → Broadcast Upload Extension 并填写所需信息。
将扩展添加到一个 app group:
- 转到项目中该扩展的 target。
- 在 Signing & Capabilities 选项卡中,选择 +。
- 添加 App Groups。
- 将 App Groups 添加到主应用,两个 target 使用相同的标识符。
编辑你的 SampleHandler 类:
import RealtimeKit
class SampleHandler: RtkSampleHandler {}你可以在 GitHub ↗ 上找到 RtkSampleHandler 的源码以及 ScreenShareExtension 的完整实现。
确保应用和扩展的 Info.plist 文件都包含这些键:
<key>RTKRTCAppGroupIdentifier</key>
<string>(name of the group you have created)</string>将此键添加到主应用的 Info.plist:
<key>RTKRTCScreenSharingExtension</key>
<string>(Bundle Identifier of the Broadcast Upload Extension)</string>启动 Broadcast Upload Extension 并启用屏幕共享:
meeting.localUser.enableScreenShare()要停止屏幕共享:
meeting.localUser.disableScreenShare()在 Xcode 中,通过 File → New → Target 添加 Broadcast Upload Extension。选择 iOS → Broadcast Upload Extension 并填写所需信息。
将扩展添加到一个 app group:
- 转到项目中该扩展的 target。
- 在 Signing & Capabilities 选项卡中,选择 + 并添加 App Groups。
- 将相同的 App Group 添加到主应用 target,两个 target 使用相同的标识符。
SDK 包含一个 Ruby 辅助脚本,可将所需的屏幕共享 Swift 源文件添加到你的 Broadcast Upload Extension target。将以下内容添加到 Podfile:
# Add this line at the top
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"@cloudflare/realtimekit-react-native/ios/scripts/screenshare_sources.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip
target 'YourApp' do
...
post_install do |installer|
...
# Add this line here
add_screenshare_sources(
installer,
project_name: 'YourApp', # your Xcode project name (without .xcodeproj)
extension_target_name: 'YourAppScreenshare' # your Broadcast Upload Extension target name
)
...
end
end
target 'YourAppScreenshare' do
# Remove the old steps added if any
end然后运行:
pod install在 Broadcast Upload Extension 中,编辑 SampleHandler.swift:
class SampleHandler: RTKScreenshareHandler {
override init() {
super.init(
appGroupIdentifier: "<YOUR_APP_GROUP_IDENTIFIER>",
bundleIdentifier: "<YOUR_APP_BUNDLE_IDENTIFIER>"
)
}
}将 <YOUR_APP_GROUP_IDENTIFIER> 替换为你创建的 App Group。将 <YOUR_APP_BUNDLE_IDENTIFIER> 替换为主应用的 bundle identifier。
将以下键添加到主应用和扩展的 Info.plist 文件:
<key>RTCAppGroupIdentifier</key>
<string>(YOUR_APP_GROUP_IDENTIFIER)</string>仅将此键添加到主应用的 Info.plist:
<key>RTCAppScreenSharingExtension</key>
<string>(Bundle Identifier of the Broadcast Upload Extension)</string>meeting.self.enableScreenShare();要停止屏幕共享:
meeting.self.disableScreenShare();