// // ScreenStreamPlugin.m // Runner // // Created by Drew on 2019/5/9. // Copyright © 2019 The Chromium Authors. All rights reserved. // #import "ScreenStreamPlugin.h" #import #import @interface ScreenStreamPlugin() @property (nonatomic) UIViewController *viewController; @end @implementation ScreenStreamPlugin + (void)registerWithRegistrar:(NSObject*)registrar { FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"screen_stream" binaryMessenger:[registrar messenger]]; UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController; ScreenStreamPlugin* instance = [[ScreenStreamPlugin alloc] initWithViewController:viewController]; [registrar addMethodCallDelegate:instance channel:channel]; } - (instancetype)initWithViewController:(UIViewController *)viewController { self = [super init]; if(self) { self.viewController = viewController; } return self; } - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"start" isEqualToString:call.method]) { NSString *playerInfoId = [call.arguments[@"playerInfoId"] stringValue]; NSString *rtmpUrl = [NSString stringWithFormat:@"rtmp://47.96.141.102:1935/myapp/%@", playerInfoId]; NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.izouma.wnnaBattle"]; [userDefaults setValue:rtmpUrl forKey:@"rtmpUrl"]; [userDefaults synchronize]; CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("PUSH_START"), NULL, nil, YES); if (@available(iOS 12.0, *) ) { } result(@"success"); } else if ([@"stop" isEqualToString:call.method]) { NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.izouma.wnnaBattle"]; [userDefaults removeObjectForKey:@"rtmpUrl"]; CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("PUSH_STOP"), NULL, nil, YES); result(@"success"); } else if ([@"prepare" isEqualToString:call.method]) { result(@"success"); } } @end