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. #import "PCSBaseViewController.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. PCSBaseViewController *vc = [PCSBaseViewController initWithParams:params complete:^(NSDictionary * _Nonnull dict) {
  24. if (complete) {
  25. complete(dict);
  26. }
  27. }];
  28. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  29. [presentVC presentViewController:vc animated:YES completion:nil];
  30. } else {
  31. dispatch_async(dispatch_get_main_queue(), ^{
  32. PCSBaseViewController *vc = [PCSBaseViewController initWithParams:params complete:^(NSDictionary * _Nonnull dict) {
  33. if (complete) {
  34. complete(dict);
  35. }
  36. }];
  37. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  38. [presentVC presentViewController:vc animated:YES completion:nil];
  39. });
  40. }
  41. }
  42. + (UIViewController * __nullable)topmostViewController {
  43. UIViewController *topViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
  44. if (topViewController == nil) {
  45. return nil;
  46. }
  47. while (true) {
  48. if (topViewController.presentedViewController != nil) {
  49. topViewController = topViewController.presentedViewController;
  50. } else if ([topViewController isKindOfClass:[UINavigationController class]]) {
  51. UINavigationController *navi = (UINavigationController *)topViewController;
  52. topViewController = navi.topViewController;
  53. } else if ([topViewController isKindOfClass:[UITabBarController class]]) {
  54. UITabBarController *tab = (UITabBarController *)topViewController;
  55. topViewController = tab.selectedViewController;
  56. } else {
  57. break;
  58. }
  59. }
  60. return topViewController;
  61. }
  62. @end