ScreenStreamPlugin.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // ScreenStreamPlugin.m
  3. // Runner
  4. //
  5. // Created by Drew on 2019/5/9.
  6. // Copyright © 2019 The Chromium Authors. All rights reserved.
  7. //
  8. #import "ScreenStreamPlugin.h"
  9. #import <ReplayKit/ReplayKit.h>
  10. #import <NotificationCenter/NotificationCenter.h>
  11. #import "SCLAlertView.h"
  12. @interface ScreenStreamPlugin() <FlutterPlugin>
  13. @property (nonatomic) UIViewController *viewController;
  14. @end
  15. @implementation ScreenStreamPlugin
  16. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  17. FlutterMethodChannel* channel = [FlutterMethodChannel
  18. methodChannelWithName:@"screen_stream"
  19. binaryMessenger:[registrar messenger]];
  20. UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  21. ScreenStreamPlugin* instance = [[ScreenStreamPlugin alloc] initWithViewController:viewController];
  22. [registrar addMethodCallDelegate:instance channel:channel];
  23. }
  24. - (instancetype)initWithViewController:(UIViewController *)viewController {
  25. self = [super init];
  26. if(self) {
  27. self.viewController = viewController;
  28. }
  29. return self;
  30. }
  31. - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
  32. if ([@"start" isEqualToString:call.method]) {
  33. // NSString *playerInfoId = call.arguments[@"playerInfoId"];
  34. // NSString *rtmpUrl = [NSString stringWithFormat:@"rtmp://202.79.174.56:1935/myapp/%@?playerInfoId=%@", playerInfoId, playerInfoId];
  35. // NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.long.dianjing"];
  36. // [userDefaults setValue:rtmpUrl forKey:@"rtmpUrl"];
  37. // [userDefaults synchronize];
  38. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("PUSH_START"), NULL, nil, YES);
  39. SCLAlertView *alert = [[SCLAlertView alloc] init];
  40. alert.labelTitle.font = [UIFont systemFontOfSize:14];
  41. NSString *appName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"];
  42. [alert addButton:@"OK" actionBlock:^{
  43. result(@"success");
  44. }];
  45. if (@available(iOS 12.0, *) ) {
  46. RPSystemBroadcastPickerView *pickerView = [[RPSystemBroadcastPickerView alloc] initWithFrame:CGRectMake(0, 0, 216, 80)];
  47. pickerView.preferredExtension = @"com.long.dianjing.ScreenRecorder";
  48. [alert addCustomView:pickerView];
  49. [alert showNotice:self.viewController title:[NSString stringWithFormat:@"点击下方图标开始录屏,或在上拉控制中心选择%@开始录屏", appName] subTitle:nil closeButtonTitle:nil duration:0.0f];
  50. } else {
  51. [alert showNotice:self.viewController title:[NSString stringWithFormat:@"请上拉呼出控制中心选择%@开始录屏", appName] subTitle:nil closeButtonTitle:nil duration:0.0f];
  52. }
  53. } else if ([@"stop" isEqualToString:call.method]) {
  54. NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.long.dianjing"];
  55. [userDefaults removeObjectForKey:@"rtmpUrl"];
  56. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("PUSH_STOP"), NULL, nil, YES);
  57. result(@"success");
  58. } else if ([@"prepare" isEqualToString:call.method]) {
  59. result(@"success");
  60. }
  61. }
  62. @end