AppDelegate.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. if (rotationRatey > 7){
  45. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Consn_Fanzhuan_Exit_app_Open];
  46. if (haveOpenMask){
  47. exit(0);/*强制退出app*/
  48. }
  49. }
  50. }];
  51. [[ShearDeviceUDPManager shareInstance] startShearchDevice];
  52. [[ShearDeviceUDPManager shareInstance] shearchDeviceLoop];
  53. return YES;
  54. }
  55. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  56. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  57. return UIInterfaceOrientationMaskPortrait;
  58. }
  59. #pragma mark - UISceneSession lifecycle
  60. - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
  61. // Called when a new scene session is being created.
  62. // Use this method to select a configuration to create the new scene with.
  63. return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  64. }
  65. - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
  66. // Called when the user discards a scene session.
  67. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  68. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  69. }
  70. - (void)applicationWillEnterForeground:(UIApplication *)application {
  71. // 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.
  72. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  73. NSString *orderNumber = [HWDataManager getStringWithKey:Const_AirpayOrWXorderNum];
  74. if (orderNumber && ![orderNumber isEqualToString:@""])
  75. {
  76. [[NSNotificationCenter defaultCenter] postNotificationName:NotNameAirpayOrWXorderNum object:orderNumber];
  77. }
  78. });
  79. }
  80. @end