AppDelegate.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. @interface AppDelegate (){
  11. CMMotionManager *cmManager;
  12. }
  13. @end
  14. @implementation AppDelegate
  15. + (AppDelegate*)sharedAppDelegate
  16. {
  17. static AppDelegate *appDelegate = nil;
  18. static dispatch_once_t onceToken;
  19. dispatch_once(&onceToken, ^{
  20. if (appDelegate == nil) {
  21. appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  22. }
  23. });
  24. return appDelegate;
  25. }
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  27. //设置默认值
  28. self.couldPhone_W_PHONE = 720.0;
  29. self.couldPhone_H_PHONE = 1280.0;
  30. [[UIButton appearance] setExclusiveTouch:YES];
  31. cmManager = [[CMMotionManager alloc] init];
  32. if (cmManager.isAccelerometerAvailable){
  33. HLog(@"\n-------摇一摇可用-----");
  34. }else{
  35. HLog(@"\n-------摇一摇不可用-----");
  36. }
  37. cmManager.accelerometerUpdateInterval = 0.1;
  38. [cmManager startAccelerometerUpdates];
  39. [cmManager startDeviceMotionUpdatesToQueue:[NSOperationQueue new] withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) {
  40. // CMRotationRate rotationRate = motion.rotationRate;
  41. // CGFloat rotationRatex = rotationRate.x;
  42. // CGFloat rotationRatey = rotationRate.y;
  43. // CGFloat rotationRatez = rotationRate.z;
  44. CMAcceleration accrleration = motion.gravity;
  45. CGFloat rotationGravityz = accrleration.z;
  46. //HLog(@"rotationRatey: %f",rotationRatey)
  47. //HLog(@"rotationGravityz: %f",rotationGravityz)
  48. //if (rotationRatey > 7){
  49. if (rotationGravityz > 0.85){
  50. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Consn_Fanzhuan_Exit_app_Open];
  51. if (haveOpenMask){
  52. exit(0);/*强制退出app*/
  53. }
  54. }
  55. }];
  56. // [[ShearDeviceUDPManager shareInstance] startShearchDevice];
  57. // [[ShearDeviceUDPManager shareInstance] shearchDeviceLoop];
  58. return YES;
  59. }
  60. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  61. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  62. return UIInterfaceOrientationMaskPortrait;
  63. }
  64. #pragma mark - UISceneSession lifecycle
  65. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
  66. // Called when a new scene session is being created.
  67. // Use this method to select a configuration to create the new scene with.
  68. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  69. }
  70. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
  71. // Called when the user discards a scene session.
  72. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  73. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  74. }
  75. - (void)applicationWillEnterForeground:(UIApplication *)application {
  76. // 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.
  77. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  78. NSString *orderNumber = [HWDataManager getStringWithKey:Const_AirpayOrWXorderNum];
  79. if (orderNumber && ![orderNumber isEqualToString:@""])
  80. {
  81. [[NSNotificationCenter defaultCenter] postNotificationName:NotNameAirpayOrWXorderNum object:orderNumber];
  82. }
  83. });
  84. }
  85. @end