WebviewController.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // WebviewController.m
  3. // Pods
  4. //
  5. // Created by Toufik Zitouni on 6/17/17.
  6. //
  7. //
  8. #import "WebviewController.h"
  9. #import "FlutterWebviewPlugin.h"
  10. @interface WebviewController ()
  11. @property (nonatomic, retain) NSString *url;
  12. @property NSNumber *withJavascript;
  13. @property NSNumber *clearCache;
  14. @property NSNumber *clearCookies;
  15. @property NSNumber *fullScreen;
  16. @end
  17. @implementation WebviewController
  18. - (instancetype)initWithUrl:(NSString *)url withJavascript:(NSNumber *)withJavascript clearCache:(NSNumber *)clearCache clearCookes:(NSNumber *)clearCookies fullScreen:(NSNumber *)fullScreen {
  19. self = [super init];
  20. if (self) {
  21. self.url = url;
  22. self.withJavascript = withJavascript;
  23. self.clearCache = clearCache;
  24. self.clearCookies = clearCookies;
  25. self.fullScreen = fullScreen;
  26. }
  27. return self;
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(backButtonPressed:)];
  32. self.navigationItem.leftBarButtonItem = backButton;
  33. UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
  34. if ([self.clearCache boolValue]) {
  35. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  36. }
  37. if ([self.clearCookies boolValue]) {
  38. [[NSURLSession sharedSession] resetWithCompletionHandler:^{
  39. }];
  40. }
  41. [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
  42. webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  43. [self.view addSubview:webView];
  44. }
  45. - (void)viewWillAppear:(BOOL)animated {
  46. [super viewWillAppear:animated];
  47. if ([self.fullScreen boolValue]) {
  48. [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
  49. }
  50. }
  51. - (IBAction)backButtonPressed:(id)sender {
  52. [channel invokeMethod:@"onBackPressed" arguments:nil];
  53. [self dismissViewControllerAnimated:YES completion:nil];
  54. }
  55. - (void)dealloc {
  56. [channel invokeMethod:@"onDestroy" arguments:nil];
  57. }
  58. @end