AppDelegate.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // AppDelegate.m
  3. // Temperature
  4. //
  5. // Created by RD on 2022/10/21.
  6. //
  7. #import "AppDelegate.h"
  8. #import "RDSHomeVC.h"
  9. #import "RDSRootControl.h"
  10. #import <MMKV/MMKV.h>
  11. #import <WebKit/WebKit.h>
  12. #import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h>
  13. @interface AppDelegate ()
  14. @property (nonatomic, strong) WKWebView *webView;
  15. @end
  16. @implementation AppDelegate
  17. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  18. // Override point for customization after application launch.
  19. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  20. self.window.rootViewController = [RDSRootControl shareControl].rootViewController;
  21. [self.window makeKeyAndVisible];
  22. self.window.backgroundColor = RDSViewBgColor;
  23. self.flutterEngine = [[FlutterEngine alloc] initWithName:@"my flutter engine"];
  24. // Runs the default Dart entrypoint with a default Flutter route.
  25. [self.flutterEngine run];
  26. // Connects plugins with iOS platform code to this app.
  27. [GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];
  28. // return [super application:application didFinishLaunchingWithOptions:launchOptions];
  29. // 初始化MMKV
  30. // [MMKV initializeMMKV:nil];
  31. // 设置全局userAgent
  32. self.webView = [[WKWebView alloc] init];
  33. [_webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  34. NSString *newUserAgent = [result stringByAppendingFormat:@"/%@", @"yongxulvjian"];
  35. [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent":newUserAgent}];
  36. }];
  37. [RDSDemoApiHelper rds_appInitSuccess:^(id responseObject) {
  38. } failure:^(NSError *error) {
  39. }];
  40. // 自动登录
  41. if(!kNULLString(TheDataManager.token)){
  42. [RDSDemoApiHelper rds_refreshTokenSuccess:^(id responseObject) {
  43. if ([responseObject[@"code"] intValue] == 0) {
  44. [RDSRootControl shareControl].isLoginSuccess = YES;
  45. NSDictionary *data = responseObject[@"data"];
  46. TheDataManager.token = [NSString stringWithFormat:@"%@ %@",data[@"token_type"], data[@"access_token"]];
  47. } else{
  48. }
  49. } failure:^(NSError *error) {
  50. }];
  51. }
  52. [RDSHudShower setupHUD];
  53. // 启动图片延时1秒
  54. [NSThread sleepForTimeInterval:1];
  55. // NSString *language = [[NSUserDefaults standardUserDefaults] valueForKey:@"AppleLanguages"];
  56. // DDLog(@"系统语言:%@",language);
  57. // [[NSUserDefaults standardUserDefaults] setObject:@[@"zh-Hans"] forKey:@"AppleLanguages"];
  58. // [[NSUserDefaults standardUserDefaults] synchronize];
  59. return YES;
  60. }
  61. @end