AppDelegate.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // AppDelegate.m
  3. // 唔即云相册
  4. //
  5. // Created by 余衡武 on 2021/12/8.
  6. //
  7. #import "AppDelegate.h"
  8. #import <CoreMotion/CoreMotion.h>
  9. #import "ShearDeviceUDPManager.h"
  10. #import "AudioSessionObject.h"
  11. #import "DDYLanguageTool.h"
  12. #import "AFNetworkReachabilityManager.h"
  13. #import "PLeakSniffer.h"
  14. #import "connectDeviceManager.h"
  15. #import <Bugly/Bugly.h>
  16. @interface AppDelegate (){
  17. CMMotionManager *cmManager;
  18. }
  19. @end
  20. @implementation AppDelegate
  21. + (AppDelegate*)sharedAppDelegate
  22. {
  23. static AppDelegate *appDelegate = nil;
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. if (appDelegate == nil) {
  27. appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  28. }
  29. });
  30. return appDelegate;
  31. }
  32. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  33. [self setLanguagesFun];
  34. //设置默认值
  35. // self.couldPhone_W_PHONE = 720.0;
  36. // self.couldPhone_H_PHONE = 1280.0;
  37. self.couldPhone_W_PHONE = 1080.0;
  38. self.couldPhone_H_PHONE = 1920.0;
  39. [[UIButton appearance] setExclusiveTouch:YES];
  40. cmManager = [[CMMotionManager alloc] init];
  41. if (cmManager.isAccelerometerAvailable){
  42. HLog(@"\n-------摇一摇可用-----");
  43. }else{
  44. HLog(@"\n-------摇一摇不可用-----");
  45. }
  46. cmManager.accelerometerUpdateInterval = 0.1;
  47. [cmManager startAccelerometerUpdates];
  48. [cmManager startDeviceMotionUpdatesToQueue:[NSOperationQueue new] withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) {
  49. // CMRotationRate rotationRate = motion.rotationRate;
  50. // CGFloat rotationRatex = rotationRate.x;
  51. // CGFloat rotationRatey = rotationRate.y;
  52. // CGFloat rotationRatez = rotationRate.z;
  53. CMAcceleration accrleration = motion.gravity;
  54. CGFloat rotationGravityz = accrleration.z;
  55. //HLog(@"rotationRatey: %f",rotationRatey)
  56. //HLog(@"rotationGravityz: %f",rotationGravityz)
  57. //if (rotationRatey > 7){
  58. if (rotationGravityz > 0.85){
  59. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Consn_Fanzhuan_Exit_app_Open];
  60. BOOL isPrivacyMode = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode;
  61. if (haveOpenMask && isPrivacyMode){
  62. exit(0);/*强制退出app*/
  63. }
  64. }
  65. }];
  66. // [[ShearDeviceUDPManager shareInstance] startShearchDevice];
  67. // [[ShearDeviceUDPManager shareInstance] shearchDeviceLoop];
  68. //启动后台保活
  69. [AudioSessionObject shareManager];
  70. [self MonitorNetworkChangesFun];
  71. #ifdef DEBUG
  72. [[PLeakSniffer sharedInstance] installLeakSniffer];
  73. #else
  74. [Bugly startWithAppId:@"179559a521"];
  75. #endif
  76. return YES;
  77. }
  78. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  79. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  80. return UIInterfaceOrientationMaskPortrait;
  81. }
  82. #pragma mark - UISceneSession lifecycle
  83. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
  84. // Called when a new scene session is being created.
  85. // Use this method to select a configuration to create the new scene with.
  86. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  87. }
  88. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
  89. // Called when the user discards a scene session.
  90. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  91. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  92. }
  93. - (void)applicationWillEnterForeground:(UIApplication *)application {
  94. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  95. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  96. NSString *orderNumber = [HWDataManager getStringWithKey:Const_AirpayOrWXorderNum];
  97. if (orderNumber && ![orderNumber isEqualToString:@""])
  98. {
  99. [[NSNotificationCenter defaultCenter] postNotificationName:NotNameAirpayOrWXorderNum object:orderNumber];
  100. }
  101. });
  102. }
  103. #pragma mark 监听网络变化
  104. -(void)MonitorNetworkChangesFun
  105. {
  106. [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  107. HLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
  108. [[NSNotificationCenter defaultCenter] postNotificationName:NetWorkChangeNotification object:nil];
  109. }];
  110. [[AFNetworkReachabilityManager sharedManager] startMonitoring];
  111. }
  112. #pragma mark 多国语言相关
  113. -(void)setLanguagesFun{
  114. NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
  115. NSLog(@"arLanguages:%@",arLanguages);
  116. ///获取设备当前地区的代码和APP语言环境
  117. NSString *languageCode = [NSLocale preferredLanguages][0];
  118. // 获取国际通用国家地区代码(应该和手机本身有关)
  119. NSString *countryCode = [NSString stringWithFormat:@"-%@", [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]];
  120. // if (languageCode) {
  121. // languageCode = [languageCode stringByReplacingOccurrencesOfString:countryCode withString:@""];
  122. // }
  123. NSLog(@"countryCode:%@ languageCode : %@",countryCode, languageCode);
  124. ///当前APP使用的语言
  125. NSString *preferredLanguage = [[[NSBundle mainBundle] preferredLocalizations] firstObject];
  126. //获取设备当前地区的代码和APP语言环境
  127. NSString *localeIdentifier = [[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
  128. NSLog(@"preferredLanguage:%@ localeIdentifier : %@",preferredLanguage, localeIdentifier);
  129. //目前支持 中文(简体 繁体) 英文 日语(还没做)
  130. if([languageCode rangeOfString:preferredLanguage].location != NSNotFound){
  131. // if([preferredLanguage rangeOfString:@"ja"].location != NSNotFound){
  132. // //日文现在也显示英文
  133. // [self setDefaultEnglishFun];
  134. // }
  135. // else
  136. {
  137. [DDYLanguageTool ddy_SetLanguage:@"" complete:^(NSError *error) {
  138. // 刷新rootVC等
  139. }];
  140. }
  141. }
  142. else{
  143. [self setDefaultEnglishFun];
  144. }
  145. }
  146. #pragma mark 设置当前显示语言为中文
  147. - (void)setDefaultEnglishFun{
  148. //默认设为英文
  149. [DDYLanguageTool ddy_SetLanguage:@"en" complete:^(NSError *error) {
  150. // 刷新rootVC等
  151. }];
  152. }
  153. @end