#import <ReplayKit/ReplayKit.h>@interfaceBroadcastViewController : UIViewController@end...-(IBAction)onCancelButtonPressed:(id)sender{[selfuserDidCancelSetup];}-(IBAction)onOKButtonPressed:(id)sender{if(self.accountTextField.text.length==0||self.passwordTextField.text.length==0||self.channelIDTextField.text.length==0){return;}[selfuserDidFinishSetup];}#pragma mark - Private// Called when the user has finished interacting with the view controller and a broadcast stream can start-(void)userDidFinishSetup{NSLog(@"userDidFinishSetup");// Broadcast url that will be returned to the applicationNSURL*broadcastURL=[NSURLURLWithString:@"http://broadcastURL_example/stream1"];// Service specific broadcast data example which will be supplied to the process extension during broadcastNSDictionary*setupInfo=@{@"account":self.accountTextField.text,@"password":self.passwordTextField.text,@"channelID":@(self.channelIDTextField.text.integerValue)};// Set broadcast settingsRPBroadcastConfiguration*broadcastConfig=[[RPBroadcastConfigurationalloc]init];broadcastConfig.clipDuration=5.0;// deliver movie clips every 5 seconds// Tell ReplayKit that the extension is finished setting up and can begin broadcasting[self.extensionContextcompleteRequestWithBroadcastURL:broadcastURLbroadcastConfiguration:broadcastConfigsetupInfo:setupInfo];}-(void)userDidCancelSetup{// Tell ReplayKit that the extension was cancelled by the user[self.extensionContextcancelRequestWithError:[NSErrorerrorWithDomain:@"YourAppDomain"code:-1userInfo:nil]];}
#import <ReplayKit/ReplayKit.h>@interfaceSampleHandler : RPBroadcastSampleHandler@end...// To handle samples with a subclass of RPBroadcastSampleHandler set the following in the extension's Info.plist file:// - RPBroadcastProcessMode should be set to RPBroadcastProcessModeSampleBuffer// - NSExtensionPrincipalClass should be set to this class@implementationSampleHandler-(void)broadcastStartedWithSetupInfo:(NSDictionary<NSString*,NSObject*>*)setupInfo{// User has requested to start the broadcast. Setup info from the UI extension will be supplied.NSLog(@"broadcastStartedWithSetupInfo: %@",setupInfo);[[ReplayKitUploadersharedObject]setupWithInfo:setupInfo];}-(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)sampleBufferwithType:(RPSampleBufferType)sampleBufferType{[[ReplayKitUploadersharedObject]handleSampleBuffer:sampleBufferwithType:sampleBufferType];}@end