LenzCameraSDK.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // LenzCameraSDK.m
  3. // LenzCameraNativeModuleForRN
  4. //
  5. // Created by lr on 2023/3/16.
  6. //
  7. #import "LenzCameraSDK.h"
  8. @implementation LenzCameraSDK
  9. + (void)showCameraSDKWithParams:(NSDictionary *)params
  10. complete:(LenzCameraSDKComplete)complete {
  11. dispatch_async(dispatch_get_main_queue(), ^{
  12. UIViewController *vc = [LenzCameraSDK topmostViewController];
  13. if (vc) {
  14. [LenzCameraSDK showCameraSDKWithParams:params presentVC:vc complete:complete];
  15. }
  16. });
  17. }
  18. + (void)showCameraSDKWithParams:(NSDictionary *)params
  19. presentVC:(__kindof UIViewController *)presentVC
  20. complete:(LenzCameraSDKComplete)complete {
  21. if ([NSThread isMainThread]) {
  22. __block PCSBaseViewController *vc = [PCSBaseViewController initWithParams:params complete:^(NSDictionary * _Nonnull dict) {
  23. if (complete) {
  24. complete(dict);
  25. }
  26. vc = nil;
  27. }];
  28. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  29. [presentVC presentViewController:vc animated:YES completion:nil];
  30. } else {
  31. dispatch_async(dispatch_get_main_queue(), ^{
  32. __block PCSBaseViewController *vc = [PCSBaseViewController initWithParams:params complete:^(NSDictionary * _Nonnull dict) {
  33. if (complete) {
  34. complete(dict);
  35. }
  36. vc = nil;
  37. }];
  38. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  39. [presentVC presentViewController:vc animated:YES completion:nil];
  40. });
  41. }
  42. }
  43. + (UIViewController * __nullable)topmostViewController {
  44. UIViewController *topViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
  45. if (topViewController == nil) {
  46. return nil;
  47. }
  48. while (true) {
  49. if (topViewController.presentedViewController != nil) {
  50. topViewController = topViewController.presentedViewController;
  51. } else if ([topViewController isKindOfClass:[UINavigationController class]]) {
  52. UINavigationController *navi = (UINavigationController *)topViewController;
  53. topViewController = navi.topViewController;
  54. } else if ([topViewController isKindOfClass:[UITabBarController class]]) {
  55. UITabBarController *tab = (UITabBarController *)topViewController;
  56. topViewController = tab.selectedViewController;
  57. } else {
  58. break;
  59. }
  60. }
  61. return topViewController;
  62. }
  63. @end