2
0

LBXPermissionSetting.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // LBXPermissionSetting.m
  3. // Demo
  4. //
  5. // Created by lbx on 2017/12/8.
  6. // Copyright © 2017年 lbx. All rights reserved.
  7. //
  8. #import "LBXPermissionSetting.h"
  9. #import <UIKit/UIKit.h>
  10. @implementation LBXPermissionSetting
  11. #pragma mark- disPlayAppPrivacySetting
  12. + (void)displayAppPrivacySettings
  13. {
  14. if (@available(iOS 8,*))
  15. {
  16. if (UIApplicationOpenSettingsURLString != NULL)
  17. {
  18. NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  19. if (@available(iOS 10,*)) {
  20. [[UIApplication sharedApplication]openURL:appSettings options:@{} completionHandler:^(BOOL success) {
  21. }];
  22. }
  23. else
  24. {
  25. [[UIApplication sharedApplication]openURL:appSettings];
  26. }
  27. }
  28. }
  29. }
  30. /**
  31. show dialog to guide user to show App privacy setting
  32. @param title title
  33. @param message privacy message
  34. @param cancel cancel button text
  35. @param setting setting button text,if user tap this button ,will show App privacy setting
  36. */
  37. + (void)showAlertToDislayPrivacySettingWithTitle:(NSString*)title
  38. msg:(NSString*)message
  39. cancel:(NSString*)cancel
  40. setting:(NSString*)setting
  41. {
  42. [self showAlertToDislayPrivacySettingWithTitle:title msg:message cancel:cancel setting:setting completion:nil];
  43. }
  44. /**
  45. show dialog to guide user to show App privacy setting
  46. @param title title
  47. @param message privacy message
  48. @param cancel cancel button text
  49. @param setting setting button text,if user tap this button ,will show App privacy setting
  50. @param completion user has been choosed
  51. */
  52. + (void)showAlertToDislayPrivacySettingWithTitle:(NSString*)title
  53. msg:(NSString*)message
  54. cancel:(NSString*)cancel
  55. setting:(NSString*)setting
  56. completion:(void(^)(void))completion
  57. {
  58. if (@available(iOS 8,*)) {
  59. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  60. //cancel
  61. UIAlertAction *action = [UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  62. if (completion) {
  63. completion();
  64. }
  65. }];
  66. [alertController addAction:action];
  67. //ok
  68. UIAlertAction *okAction = [UIAlertAction actionWithTitle:setting style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  69. if (completion) {
  70. completion();
  71. }
  72. [self displayAppPrivacySettings];
  73. }];
  74. [alertController addAction:okAction];
  75. [[self currentTopViewController] presentViewController:alertController animated:YES completion:nil];
  76. }
  77. }
  78. + (UIViewController*)currentTopViewController
  79. {
  80. UIViewController *currentViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  81. while ([currentViewController presentedViewController]) currentViewController = [currentViewController presentedViewController];
  82. if ([currentViewController isKindOfClass:[UITabBarController class]]
  83. && ((UITabBarController*)currentViewController).selectedViewController != nil )
  84. {
  85. currentViewController = ((UITabBarController*)currentViewController).selectedViewController;
  86. }
  87. while ([currentViewController isKindOfClass:[UINavigationController class]]
  88. && [(UINavigationController*)currentViewController topViewController])
  89. {
  90. currentViewController = [(UINavigationController*)currentViewController topViewController];
  91. }
  92. return currentViewController;
  93. }
  94. @end