SupportViewController.m 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "SupportViewController.h"
  21. #import "MyIdentityStore.h"
  22. #import "Utils.h"
  23. #import "MBProgressHUD.h"
  24. #import "BundleUtil.h"
  25. @interface SupportViewController ()
  26. @end
  27. @implementation SupportViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.webView = [[WKWebView alloc] initWithFrame:self.view.frame];
  31. self.webView.allowsLinkPreview = NO;
  32. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  33. self.webView.navigationDelegate = self;
  34. [self.view addSubview:self.webView];
  35. }
  36. - (void)viewWillAppear:(BOOL)animated {
  37. [super viewWillAppear:animated];
  38. NSURL *supportUrl = nil;
  39. if ([MyIdentityStore sharedMyIdentityStore].licenseSupportUrl.length > 0) {
  40. supportUrl = [NSURL URLWithString:[MyIdentityStore sharedMyIdentityStore].licenseSupportUrl];
  41. }
  42. if (supportUrl == nil) {
  43. NSMutableArray *queryItems = [[NSMutableArray alloc] init];
  44. [queryItems addObject:[NSURLQueryItem queryItemWithName:@"lang" value:[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]]];
  45. [queryItems addObject:[NSURLQueryItem queryItemWithName:@"version" value:[Utils getClientVersion]]];
  46. [queryItems addObject:[NSURLQueryItem queryItemWithName:@"identity" value:[MyIdentityStore sharedMyIdentityStore].identity]];
  47. NSURLComponents *components = [NSURLComponents componentsWithString:[BundleUtil objectForInfoDictionaryKey:@"ThreemaSupportURL"]];
  48. components.queryItems = queryItems;
  49. supportUrl = components.URL;
  50. }
  51. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  52. [self.webView loadRequest:[NSURLRequest requestWithURL:supportUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15]];
  53. }
  54. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  55. [MBProgressHUD hideHUDForView:self.view animated:YES];
  56. }
  57. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  58. if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
  59. if (navigationAction.request.URL != nil) {
  60. [[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:nil];
  61. decisionHandler(WKNavigationActionPolicyCancel);
  62. return;
  63. }
  64. }
  65. decisionHandler(WKNavigationActionPolicyAllow);
  66. }
  67. - (BOOL)shouldAutorotate {
  68. return YES;
  69. }
  70. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  71. if (SYSTEM_IS_IPAD) {
  72. return UIInterfaceOrientationMaskAll;
  73. }
  74. return UIInterfaceOrientationMaskAllButUpsideDown;
  75. }
  76. @end