日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

重要

本文中含有需要您注意的重要提示信息,忽略該信息可能對您的業務造成影響,請務必仔細閱讀。

通過閱讀本文,您可以了解 iOS 如何實現屏幕共享。DingRTC 的屏幕共享方案是基于 iOS 系統的 ReplayKit,能夠分享整個系統的屏幕內容,但需要在您的 App 里額外創建一個 Extension 擴展組件。

一、創建 Broadcast Upload Extension

  1. 在 Xcode 菜單依次單擊 File -> New -> Target,選擇 Broadcast Upload Extension。

image

  1. 選中新建的 Target,單擊 Capability添加 App Groups,如下圖:

image

3. 填寫 App Group Id,如下圖。這一步要求您需要持有 Apple 的開發證書或個人賬號。image

  1. 選中主 App 的 Target ,并按照上述的步驟 2、3 對主 App 的 Target 做同樣的處理。

  2. 選中新建的 Target,添加 DingRTC.framework 到 Framework and Libraries,如下圖:

image

6. 在新建的 Target 中,Xcode 會自動創建一個名為 SampleHandler.m 的文件,用如下代碼進行替換。需將代碼中的 kAppGroup 修改為上文中您填寫的 App Group Id

#import "SampleHandler.h"
#import <DingRtc/DingRTC.h>

static NSString * _Nonnull kAppGroup = @"group.com.dingtalk.DingRTCSample";

@interface SampleHandler() <DingScreenShareExtDelegate>

@end

@implementation SampleHandler

- (void)broadcastStartedWithSetupInfo:(NSDictionary<NSString *,NSObject *> *)setupInfo {
    // User has requested to start the broadcast. Setup info from the UI extension can be supplied but optional.
    [[DingRtcScreenShareExt sharedInstance] setupWithAppGroup:kAppGroup delegate:self];
}

- (void)broadcastPaused {
    // User has requested to pause the broadcast. Samples will stop being delivered.
}

- (void)broadcastResumed {
    // User has requested to resume the broadcast. Samples delivery will resume.
}

- (void)broadcastFinished {
    // User has requested to finish the broadcast.
}

- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType {
    @autoreleasepool {
        [[DingRtcScreenShareExt sharedInstance] sendSampleBuffer:sampleBuffer type:sampleBufferType];
    }
}

#pragma mark - DingRtcScreenShareExtDelegate

- (void)finishBroadcastWithError:(DingRtcScreenShareExt *)broadcast error:(NSError *)error {
    [self finishBroadcastWithError:error];
}

@end

二、主 App 接收來自 Broadcast Upload Extension 進程的錄屏數據

1. 在主 App 調用 -startScreenShare:mode: 傳入上文的 App Group Id 來啟動屏幕共享。

[DingRTCClient.instance.rtcEngine startScreenShare:@"group.com.dingtalk.DingRTCSample" mode:DingRtcScreenShareAll];

2. 等待用戶觸發屏幕分享(一般需要用戶在 iOS 系統的控制中心,長按錄屏按鈕來觸發),此外您也可以參考如下代碼,在主 App 通過 RPSystemBroadcastPickerView 實現彈出一個啟動器供用戶確認啟動屏幕分享。

警告
  • 蘋果在 iOS 12.0 中增加了 RPSystemBroadcastPickerView 可以在應用中彈出啟動器供用戶確認啟動屏幕分享。到目前為止 RPSystemBroadcastPickerView 尚不支持自定義界面,也沒有官方的喚起方法。

  • 示例代碼的原理是通過遍歷 RPSystemBroadcastPickerView 的 Subviews 尋找 UIButton 并觸發其點擊事件。

  • 該方案不被蘋果官方推薦,并可能在新一輪的系統更新中失效,因此僅供您參考,您需要自行承擔選用此方案帶來的風險。

@property (strong, nonatomic) RPSystemBroadcastPickerView *broadcastPickerView;

- (void)launchBroadcastPickerView {
    if (@available(iOS 12.0, *)) {
        RPSystemBroadcastPickerView *pickerView = [[RPSystemBroadcastPickerView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
        pickerView.showsMicrophoneButton = NO;
        pickerView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
        NSString *pluginPath = [NSBundle mainBundle].builtInPlugInsPath;
        NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:pluginPath error:nil];
        for (NSString *content in contents) {
            if (![content hasSuffix:@".appex"]) {
                continue;
            }
            NSBundle *bundle = [NSBundle bundleWithPath:[[NSURL fileURLWithPath:pluginPath] URLByAppendingPathComponent:content].path];
            if (bundle) {
                NSString *identifier = [bundle.infoDictionary valueForKeyPath:@"NSExtension.NSExtensionPointIdentifier"];
                if ([identifier isEqualToString:@"com.apple.broadcast-services-upload"]) {
                    pickerView.preferredExtension = bundle.bundleIdentifier;
                }
            }
        }
        self.broadcastPickerView = pickerView;
        
        for (UIView *view in self.broadcastPickerView.subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
                [(UIButton *)view sendActionsForControlEvents:UIControlEventAllEvents];
            }
        }
    }
}

3. 調用 -stopScreenShare 可以隨時停止屏幕共享。

[DingRTCClient.instance.rtcEngine stopScreenShare];