LenzCameraSDK.m 2.6 KB

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