I want to use iOS broadcast for screen sharing. I ...
# ask-ai
c
I want to use iOS broadcast for screen sharing. I am using the livekit swift sdk with cocoapods. You can refer to the documentation in https://github.com/livekit/client-sdk-swift/blob/main/Docs/ios-screen-sharing.md When building the project in xcode, I'm running into some issues with the SampleHandler.swift part, particularly about some problems with camera access (part of LiveKit import), but with apple's restrictions since it's part of an extension and not the main app. Please suggest some ideas on how to fix this
t
Thanks for reaching out, Nathan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's work together to resolve the issues you're experiencing with iOS broadcast screen sharing using the LiveKit Swift SDK. Here are some important steps to check: 1. First, please replace the default
SampleHandler.swift
content in your Broadcast Upload Extension with this code:
Copy code
import LiveKit

#if os(iOS)
@available(macCatalyst 13.1, *)
class SampleHandler: LKSampleHandler {
    override var enableLogging: Bool { true }
}
#endif
This snippet uses the
LKSampleHandler
class, which conveniently manages socket communication and ReplayKit integration for you. 1. Make sure that both your main app and the extension are part of the same App Group. You can do this by adding the App Groups capability in Xcode under Signing & Capabilities, and using the same identifier (for example,
group.com.example.myapp
). 2. Double-check that the Broadcast Upload Extension is embedded in your main app. You can find this under "Embed App Extensions" in the Build Phases tab. 3. Remember, screen sharing doesn’t require camera access because ReplayKit handles screen capture independently. So, no camera permissions are needed in your extension. 4. To help with debugging, enable logging in
SampleHandler.swift
. This way, you can monitor logs easily using the macOS Console app. If you run into any specific errors or if something isn’t clear, please feel free to share the exact log messages or describe what you’re seeing. I’m here to help you through this! Sources: Sources/LiveKit/Broadcast/LKSampleHandler.swift | example/ios/LiveKit Broadcast Extension/Info.plist | Camera & microphone | LiveKit Docs
c
but in my podfile I am using the livekit pod inside of the extension, which I believe is causing the problem. What changes (if any) should I be making to my podfile
t
Could you please share the part of your Podfile where the LiveKit pod is added for the extension? Also, if you’re facing any specific errors or build issues with this setup, I’d love to help you work through them.
c
<path>/LFVideoCapture.m6420 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
t
Thanks for sharing the details! The error you're seeing happens because the
sharedApplication
API isn’t available in iOS App Extensions. This is a common limitation since extensions run in a sandboxed environment and can’t access some APIs designed for full apps. To help you get past this, make sure the LiveKit pod is included only in your main app target—not in the Broadcast Upload Extension target. You can set this up in your Podfile like this:
Copy code
target 'MainAppTarget' do
  pod 'LiveKit'
end

target 'BroadcastExtensionTarget' do
  # Do not include LiveKit here
end
The Broadcast Upload Extension should use the shared socket communication from the main app, so it doesn’t need to include the LiveKit SDK directly. If anything’s unclear or you want a hand with this setup, just let me know—I’m here to help!
c
Now getting the "no such module 'LiveKit'" error when building, coming from the SampleHandler.swift
t
It looks like the "no such module 'LiveKit'" error is happening because the LiveKit SDK isn’t properly linked to your Broadcast Upload Extension target. Don’t worry, I’m here to help you get this sorted out! Here’s what you can do: 1. First, make sure the LiveKit SDK is added to your Broadcast Upload Extension target. In Xcode, head over to the extension’s target settings, add the LiveKit package dependency, and double-check that it’s linked to the extension. 2. Next, take a look at your
SampleHandler.swift
file. Confirm that it imports LiveKit and inherits from
LKSampleHandler
like this:
Copy code
import LiveKit

@available(macCatalyst 13.1, *)
class SampleHandler: LKSampleHandler {
    override var enableLogging: Bool { true }
}
1. Also, check your extension’s
Info.plist
file. The
NSExtensionPrincipalClass
key should be set to
$(PRODUCT_MODULE_NAME).SampleHandler
. 2. Remember that both your main app and the extension need to share the same App Group. So, add the "App Groups" capability to both targets and use the same identifier (for example,
group.com.example.myapp
). 3. Finally, ensure the ReplayKit framework is linked to the extension target. Once you’ve made these updates, try cleaning and rebuilding your project. If you’re still running into issues or if anything else pops up, please don’t hesitate to reach out—I’m here to help you through it! Sources: LiveKitExample.xcodeproj/project.pbxproj | lib/src/track/options.dart | BroadcastExtension/Info.plist | ios/LiveKitReactNativeModule.swift | swift-frontend/BroadcastExtension/Info.plist
c
how to do step 1
t
Let's walk through how to add the LiveKit SDK to your Broadcast Upload Extension target together. Here’s a simple step-by-step guide: 1. Open your project in Xcode and select the Broadcast Upload Extension target from the project navigator. 2. Head over to the Package Dependencies section in your target settings. 3. Click the + button to add a new package dependency. 4. Type in the LiveKit Swift SDK repository URL:
https://github.com/livekit/client-sdk-swift
, then click Next. 5. Pick the version that works best for you—usually the latest stable release—and click Next. 6. Make sure the Broadcast Upload Extension target is checked in the list of targets to add the package to, then hit Finish. After that, give your project a quick clean and rebuild to make sure the LiveKit module is all set up in your extension. If you run into any bumps or have questions along the way, just let me know—I’m here to help!