├── WQPermissionRequest ├── WQPermissionRequest │ ├── .DS_Store │ ├── Base.lproj │ │ └── WQLocalized.strings │ ├── en.lproj │ │ └── WQLocalized.strings │ ├── WQPermissionRequest.h │ └── WQPermissionRequest.m ├── ViewController.h ├── PrefixHeader.pch ├── AppDelegate.h ├── main.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── AppDelegate.m ├── ViewController.m └── WQLog │ ├── WQLog.h │ └── WQLog.m ├── WQPermissionRequest.xcodeproj ├── xcuserdata │ └── admin.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── WQPermissionRequest.xcscheme ├── project.xcworkspace │ └── contents.xcworkspacedata └── project.pbxproj ├── WQPermissionRequestTests ├── Info.plist └── WQPermissionRequestTests.m ├── WQPermissionRequestUITests ├── Info.plist └── WQPermissionRequestUITests.m ├── WQPermissionRequest.podspec ├── LICENSE ├── .gitignore └── README.md /WQPermissionRequest/WQPermissionRequest/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AppleDP/WQPermissionRequest/HEAD/WQPermissionRequest/WQPermissionRequest/.DS_Store -------------------------------------------------------------------------------- /WQPermissionRequest.xcodeproj/xcuserdata/admin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /WQPermissionRequest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WQPermissionRequest/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /WQPermissionRequest/PrefixHeader.pch: -------------------------------------------------------------------------------- 1 | // 2 | // PrefixHeader.pch 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/15. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #ifndef PrefixHeader_pch 10 | #define PrefixHeader_pch 11 | 12 | //#import"WQLog.h" 13 | 14 | #endif /* PrefixHeader_pch */ 15 | -------------------------------------------------------------------------------- /WQPermissionRequest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /WQPermissionRequest/WQPermissionRequest/Base.lproj/WQLocalized.strings: -------------------------------------------------------------------------------- 1 | /* 2 | WQLocalized.strings 3 | WQPermissionRequest 4 | 5 | Created by admin on 17/2/14. 6 | Copyright © 2017年 jolimark. All rights reserved. 7 | */ 8 | 9 | "Setting" = "设置"; 10 | "Don't Allow" = "禁止"; 11 | "Forbid permission" = "禁止开启权限"; 12 | "Failue authorize" = "授权失败"; 13 | "Unsuport authorize" = "不支持授权"; 14 | -------------------------------------------------------------------------------- /WQPermissionRequest/WQPermissionRequest/en.lproj/WQLocalized.strings: -------------------------------------------------------------------------------- 1 | /* 2 | WQLocalized.strings 3 | WQPermissionRequest 4 | 5 | Created by admin on 17/2/14. 6 | Copyright © 2017年 jolimark. All rights reserved. 7 | */ 8 | 9 | "Setting" = "Setting"; 10 | "Don't Allow" = "Don't Allow"; 11 | "Forbid permission" = "Forbid permission"; 12 | "Failue authorize" = "Failue authorize"; 13 | "Unsuport authorize" = "Unsuport authorize"; -------------------------------------------------------------------------------- /WQPermissionRequest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WQPermissionRequest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /WQPermissionRequestTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /WQPermissionRequestUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /WQPermissionRequest.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | WQPermissionRequest.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 84CF0BD01E5294FE001FF383 16 | 17 | primary 18 | 19 | 20 | 84CF0BE91E5294FE001FF383 21 | 22 | primary 23 | 24 | 25 | 84CF0BF41E5294FE001FF383 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /WQPermissionRequest.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | s.name = "WQPermissionRequest" 4 | s.version = "1.0.0" 5 | s.summary = "A permission request framework" 6 | s.description = <<-DESC 7 | If you are the first request a permission,the framework will call the system function to request for you. 8 | And,if you are not the first request,it will be give you note to open the permission 9 | DESC 10 | 11 | s.homepage = "https://github.com/AppleDP/WQPermissionRequest" 12 | s.license = "MIT" 13 | s.license = { :type => "MIT", :file => "LICENSE" } 14 | s.author = { "AppleDP" => "AppleDP@163.com" } 15 | s.requires_arc = true 16 | s.platform = :ios,'8.0' 17 | s.source = { :git => "https://github.com/AppleDP/WQPermissionRequest.git", :tag => s.version } 18 | s.source_files = "WQPermissionRequest/**/WQPermissionRequest/*" 19 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 AppleDP 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /WQPermissionRequestTests/WQPermissionRequestTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WQPermissionRequestTests.m 3 | // WQPermissionRequestTests 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WQPermissionRequestTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation WQPermissionRequestTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /WQPermissionRequestUITests/WQPermissionRequestUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WQPermissionRequestUITests.m 3 | // WQPermissionRequestUITests 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WQPermissionRequestUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation WQPermissionRequestUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WQPermissionRequest 2 | ### 权限判定及手动请求权限 3 | # Usage 4 | ### 支持权限类型 5 | ```objective-c 6 | typedef enum { 7 | WQPhotoLibrary, // 相册 8 | WQCamera, // 相机 9 | WQMicrophone, // 麦克风 10 | WQLocationAllows, // 始终定位 11 | WQLocationWhenInUse, // 使用时定位 12 | WQCalendars, // 日历 13 | WQReminders, // 提醒事项 14 | WQHealth, // 健康更新 15 | WQUserNotification, // 通知 16 | WQContacts, // 通讯录 17 | }WQPermission; 18 | ``` 19 | ### 权限请求 20 | ```objective-c 21 | [self.permissionRequest requestPermission:WQPhotoLibrary 22 | title:@"请求开启相册权限" 23 | description:@"开启相册权限" 24 | requestResult:^(BOOL granted, 25 | NSError *error) { 26 | if (error) { 27 | // WQLogErr(@"error: %@",error); 28 | }else { 29 | if (granted) { 30 | // WQLogMes(@"请求成功"); 31 | }else { 32 | // WQLogMes(@"请求失败"); 33 | } 34 | } 35 | }]; 36 | ``` 37 | ### 权限判定 38 | ```objective-c 39 | [self.permissionRequest determinePermission:WQPhotoLibrary]; 40 | ``` 41 | # Pod install 42 | `pod 'WQPermissionRequest', '~> 1.0.0'` 43 | -------------------------------------------------------------------------------- /WQPermissionRequest/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /WQPermissionRequest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSMicrophoneUsageDescription 6 | 开启麦克风权限 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSCameraUsageDescription 28 | 打开权限 29 | NSLocationAlwaysUsageDescription 30 | 获取位置信息 31 | NSLocationWhenInUseUsageDescription 32 | 获取实时位置信息 33 | NSPhotoLibraryUsageDescription 34 | 开启相册权限 35 | UIBackgroundModes 36 | 37 | fetch 38 | location 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIMainStoryboardFile 43 | Main 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /WQPermissionRequest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | return YES; 20 | } 21 | 22 | - (void)applicationWillResignActive:(UIApplication *)application { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | - (void)applicationDidEnterBackground:(UIApplication *)application { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | - (void)applicationWillEnterForeground:(UIApplication *)application { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | - (void)applicationWillTerminate:(UIApplication *)application { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /WQPermissionRequest/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WQPermissionRequest.h" 11 | 12 | @interface ViewController () 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | } 20 | 21 | - (IBAction)requestClick:(UIButton *)sender { 22 | __weak typeof(self) weakSelf = self; 23 | [SINGLETONREQUEST requestPermission:WQMicrophone 24 | title:@"请求开启网络权限" 25 | description:@"开启网络权限" 26 | requestResult:^(BOOL granted, 27 | NSError *error) { 28 | if (error) { 29 | }else { 30 | if (granted) { 31 | dispatch_async(dispatch_get_main_queue(), ^{ 32 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"权限已授权成功" 33 | message:@"" 34 | preferredStyle:UIAlertControllerStyleActionSheet]; 35 | UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" 36 | style:UIAlertActionStyleDefault 37 | handler:^(UIAlertAction * _Nonnull action) { 38 | }]; 39 | [alert addAction:ok]; 40 | [weakSelf.navigationController presentViewController:alert 41 | animated:YES 42 | completion:nil]; 43 | }); 44 | }else { 45 | } 46 | } 47 | }]; 48 | } 49 | @end 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /WQPermissionRequest/WQLog/WQLog.h: -------------------------------------------------------------------------------- 1 | // 2 | // WQLog.h 3 | // WQLog 4 | // 5 | // Created by admin on 16/8/25. 6 | // Copyright © 2016年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define XCODE_COLORS_ESCAPE @"\033[" 12 | #define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" 13 | 14 | /*********************************** 安 装 了 XcodeColors 后 可 以 输 出 带 颜 色 的 日 志 ***********************************/ 15 | #define WQLogDef(FORMAT,...) WQLoger(nil,(FORMAT), ## __VA_ARGS__) 16 | #define WQLogInf(FORMAT,...) WQLoger(WQColor(32,102,235,1),(FORMAT), ## __VA_ARGS__) 17 | #define WQLogErr(FORMAT,...) WQLoger(WQColor(255,0,0,1),(FORMAT), ## __VA_ARGS__) 18 | #define WQLogWar(FORMAT,...) WQLoger(WQColor(213,184,109,1),(FORMAT), ## __VA_ARGS__) 19 | #define WQLogMes(FORMAT,...) WQLoger(WQColor(127,255,0,1),(FORMAT), ## __VA_ARGS__) 20 | #define WQLogOth(FORMAT,...) WQLoger(WQColor(186,0,255,1),(FORMAT), ## __VA_ARGS__) 21 | #define WQLoger(COLOR,FORMAT,...) \ 22 | [WQLog log:COLOR \ 23 | file:[[NSString stringWithUTF8String:__FILE__] lastPathComponent] \ 24 | line:__LINE__ \ 25 | thread:[[NSThread currentThread] isMainThread] ? @"Main" : ([[NSThread currentThread].name isEqual: @""] ? @"Child" : [NSThread currentThread].name) \ 26 | log:(FORMAT), ## __VA_ARGS__] 27 | 28 | /** 自定义颜色日志输出 */ 29 | #define WQLogCus(FORMAT,...) \ 30 | [WQLog cusLog:[[NSString stringWithUTF8String:__FILE__] lastPathComponent] \ 31 | line:__LINE__ \ 32 | thread:[[NSThread currentThread] isMainThread] ? @"Main" : ([[NSThread currentThread].name isEqual: @""] ? @"Child" : [NSThread currentThread].name) \ 33 | log:(FORMAT), ## __VA_ARGS__] 34 | 35 | #define WQColor(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] 36 | 37 | @interface WQLog : NSObject 38 | /** 39 | * 将日志输出到本地 40 | */ 41 | + (void)recodeLog; 42 | /** 43 | * 清除本地日志 44 | */ 45 | + (void)clearRecode; 46 | /** 47 | * 自定义日志颜色 48 | * 49 | * @param color 日志颜色 50 | */ 51 | + (void)setCustomColor:(UIColor *)color; 52 | 53 | 54 | 55 | 56 | 57 | /*********************************** 内 部 调 用 ***********************************/ 58 | + (void)log:(UIColor *)color 59 | file:(NSString *)file 60 | line:(int)line 61 | thread:(NSString *)thread 62 | log:(NSString *)log,...; 63 | + (void)cusLog:(NSString *)file 64 | line:(int)line 65 | thread:(NSString *)thread 66 | log:(NSString *)log,...; 67 | @end 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /WQPermissionRequest/WQPermissionRequest/WQPermissionRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // WQPermissionRequest.h 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | 10 | 11 | #import 12 | 13 | #define WQLocalized(key) NSLocalizedStringFromTable(key, @"WQLocalized", nil) 14 | #define SINGLETONREQUEST [WQPermissionRequest shareWQPermissionRequest] 15 | #define WQErrorDomain @"WQErrorDomain" 16 | 17 | #ifndef WQPermissionLogEnable 18 | #define WQPermissionLogEnable 1 19 | #endif 20 | 21 | #if WQPermissionLogEnable 22 | /* 23 | 日志输出到控制台须要导入 WQLog.h 日志输出类 24 | https://github.com/AppleDP?tab=repositories 25 | */ 26 | #import "WQLog.h" 27 | #else 28 | #define WQLogDef(FORMAT,...) {} 29 | #define WQLogInf(FORMAT,...) {} 30 | #define WQLogErr(FORMAT,...) {} 31 | #define WQLogWar(FORMAT,...) {} 32 | #define WQLogMes(FORMAT,...) {} 33 | #define WQLogOth(FORMAT,...) {} 34 | #endif 35 | 36 | typedef enum { 37 | WQPhotoLibrary, // 相册 38 | WQCamera, // 相机 39 | WQMicrophone, // 麦克风 40 | WQLocationAllows, // 始终定位 41 | WQLocationWhenInUse, // 使用时定位 42 | WQCalendars, // 日历 43 | WQReminders, // 提醒事项 44 | WQHealth, // 健康更新 45 | WQUserNotification, // 通知 46 | WQContacts, // 通讯录 47 | WQNetwork, // 网络 48 | }WQPermission; 49 | 50 | typedef enum { 51 | WQForbidPermission, 52 | WQFailueAuthorize, 53 | WQUnsuportAuthorize 54 | }WQErrorCode; 55 | 56 | typedef void(^WQRequestResult)(BOOL granted, NSError *error); 57 | 58 | @interface WQPermissionRequest : NSObject 59 | + (WQPermissionRequest *)shareWQPermissionRequest; 60 | 61 | /** 62 | * 判断权限是否存在 63 | * 64 | * @param permission 权限类型 65 | * 66 | * @return 权限是否存在 67 | */ 68 | - (BOOL)determinePermission:(WQPermission)permission; 69 | 70 | /** 71 | * 获得当前活动视图控制器 72 | * 73 | * @return 当前活动视图控制器 74 | */ 75 | - (UIViewController *)currentViewController; 76 | 77 | /** 78 | * 权限是否存在,如果权限不存在则请求权限 79 | * 80 | * @param permission 权限类型 81 | * @param title 非第一次请求权限时标题 82 | * @param description 非第一次请求权限时副标题 83 | * @param result 请求结果 84 | */ 85 | - (void)requestPermission:(WQPermission)permission 86 | title:(NSString *)title 87 | description:(NSString *)description 88 | requestResult:(WQRequestResult)result; 89 | @end 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /WQPermissionRequest/WQLog/WQLog.m: -------------------------------------------------------------------------------- 1 | // 2 | // WQLog.m 3 | // WQLog 4 | // 5 | // Created by admin on 16/8/25. 6 | // Copyright © 2016年 jolimark. All rights reserved. 7 | // 8 | 9 | #import "WQLog.h" 10 | 11 | @interface WQLog () 12 | 13 | @end 14 | 15 | @implementation WQLog 16 | static UIColor *WQCustomColor; 17 | + (void)setCustomColor:(UIColor *)color { 18 | WQCustomColor = color; 19 | } 20 | 21 | + (void)recodeLog{ 22 | NSLog(@"******************************************* 开 启 日 志 *******************************************"); 23 | NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; 24 | path = [path stringByAppendingPathComponent:@"WQLog.log"]; 25 | freopen([path cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout); 26 | freopen([path cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr); 27 | NSString* date; 28 | NSDateFormatter * formatter = [[NSDateFormatter alloc ] init]; 29 | [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; 30 | date = [formatter stringFromDate:[NSDate date]]; 31 | NSString *timeNow = [[NSString alloc] initWithFormat:@"%@", date]; 32 | NSLog(@" "); 33 | NSLog(@" "); 34 | NSLog(@" "); 35 | NSLog(@"********************** 日 志 %@ **********************",timeNow); 36 | } 37 | 38 | + (void)clearRecode{ 39 | NSLog(@"******************************************* 清 除 日 志 *******************************************"); 40 | NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; 41 | path = [path stringByAppendingPathComponent:@"WQLog.log"]; 42 | NSError *err; 43 | [[NSFileManager defaultManager] removeItemAtPath:path 44 | error:&err]; 45 | } 46 | 47 | 48 | + (void)cusLog:(NSString *)file 49 | line:(int)line 50 | thread:(NSString *)thread 51 | log:(NSString *)log,... { 52 | if (WQCustomColor == nil) { 53 | WQCustomColor = [UIColor colorWithRed:0 54 | green:0 55 | blue:0 56 | alpha:0]; 57 | } 58 | [self log:WQCustomColor 59 | file:file 60 | line:line 61 | thread:thread 62 | log:log]; 63 | } 64 | 65 | + (void)log:(UIColor *)color 66 | file:(NSString *)file 67 | line:(int)line 68 | thread:(NSString *)thread 69 | log:(NSString *)log,... { 70 | va_list list; 71 | if (log) { 72 | int r = 0, g = 0, b = 0; 73 | if (color) { 74 | const CGFloat *components = CGColorGetComponents(color.CGColor); 75 | r = components[0]*255; 76 | g = components[1]*255; 77 | b = components[2]*255; 78 | } 79 | va_start(list, log); 80 | NSString *msg = [[NSString alloc] initWithFormat:log 81 | arguments:list]; 82 | va_end(list); 83 | NSLog((@"%@" 84 | @"%@" @">> >> >> 文件: %@ --- 行号: %d --- 线程: %@ --- 日志: %@ << << <<" 85 | @"%@"), 86 | color == nil ? @"" : XCODE_COLORS_ESCAPE, 87 | color == nil ? @"" : [NSString stringWithFormat:@"fg%d,%d,%d;",r,g,b], 88 | file, 89 | line, 90 | thread, 91 | msg, 92 | color == nil ? @"" : XCODE_COLORS_RESET_FG); 93 | } 94 | } 95 | @end 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /WQPermissionRequest/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /WQPermissionRequest.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/WQPermissionRequest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /WQPermissionRequest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 84832E251E6CFAC900C48F26 /* WQLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 84832E241E6CFAC900C48F26 /* WQLog.m */; }; 11 | 84CF0BD61E5294FE001FF383 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF0BD51E5294FE001FF383 /* main.m */; }; 12 | 84CF0BD91E5294FE001FF383 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF0BD81E5294FE001FF383 /* AppDelegate.m */; }; 13 | 84CF0BDC1E5294FE001FF383 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF0BDB1E5294FE001FF383 /* ViewController.m */; }; 14 | 84CF0BDF1E5294FE001FF383 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84CF0BDD1E5294FE001FF383 /* Main.storyboard */; }; 15 | 84CF0BE11E5294FE001FF383 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84CF0BE01E5294FE001FF383 /* Assets.xcassets */; }; 16 | 84CF0BE41E5294FE001FF383 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84CF0BE21E5294FE001FF383 /* LaunchScreen.storyboard */; }; 17 | 84CF0BEF1E5294FE001FF383 /* WQPermissionRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF0BEE1E5294FE001FF383 /* WQPermissionRequestTests.m */; }; 18 | 84CF0BFA1E5294FE001FF383 /* WQPermissionRequestUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF0BF91E5294FE001FF383 /* WQPermissionRequestUITests.m */; }; 19 | 84CF0C0A1E52959C001FF383 /* WQPermissionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CF0C091E52959C001FF383 /* WQPermissionRequest.m */; }; 20 | 84CF0C111E52EBE2001FF383 /* WQLocalized.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84CF0C131E52EBE2001FF383 /* WQLocalized.strings */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 84CF0BEB1E5294FE001FF383 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 84CF0BC91E5294FE001FF383 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 84CF0BD01E5294FE001FF383; 29 | remoteInfo = WQPermissionRequest; 30 | }; 31 | 84CF0BF61E5294FE001FF383 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 84CF0BC91E5294FE001FF383 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 84CF0BD01E5294FE001FF383; 36 | remoteInfo = WQPermissionRequest; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | 8456B93A1E541DA0001FC4C8 /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = ""; }; 42 | 84832E231E6CFAC900C48F26 /* WQLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WQLog.h; sourceTree = ""; }; 43 | 84832E241E6CFAC900C48F26 /* WQLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WQLog.m; sourceTree = ""; }; 44 | 84CF0BD11E5294FE001FF383 /* WQPermissionRequest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WQPermissionRequest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 84CF0BD51E5294FE001FF383 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 46 | 84CF0BD71E5294FE001FF383 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 47 | 84CF0BD81E5294FE001FF383 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 48 | 84CF0BDA1E5294FE001FF383 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 49 | 84CF0BDB1E5294FE001FF383 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 50 | 84CF0BDE1E5294FE001FF383 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | 84CF0BE01E5294FE001FF383 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52 | 84CF0BE31E5294FE001FF383 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 53 | 84CF0BE51E5294FE001FF383 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | 84CF0BEA1E5294FE001FF383 /* WQPermissionRequestTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WQPermissionRequestTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | 84CF0BEE1E5294FE001FF383 /* WQPermissionRequestTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WQPermissionRequestTests.m; sourceTree = ""; }; 56 | 84CF0BF01E5294FE001FF383 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | 84CF0BF51E5294FE001FF383 /* WQPermissionRequestUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WQPermissionRequestUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | 84CF0BF91E5294FE001FF383 /* WQPermissionRequestUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WQPermissionRequestUITests.m; sourceTree = ""; }; 59 | 84CF0BFB1E5294FE001FF383 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 60 | 84CF0C081E52959C001FF383 /* WQPermissionRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WQPermissionRequest.h; sourceTree = ""; }; 61 | 84CF0C091E52959C001FF383 /* WQPermissionRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WQPermissionRequest.m; sourceTree = ""; }; 62 | 84CF0C121E52EBE2001FF383 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/WQLocalized.strings; sourceTree = ""; }; 63 | 84CF0C141E52EBE3001FF383 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/WQLocalized.strings; sourceTree = ""; }; 64 | /* End PBXFileReference section */ 65 | 66 | /* Begin PBXFrameworksBuildPhase section */ 67 | 84CF0BCE1E5294FE001FF383 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | 84CF0BE71E5294FE001FF383 /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | 84CF0BF21E5294FE001FF383 /* Frameworks */ = { 82 | isa = PBXFrameworksBuildPhase; 83 | buildActionMask = 2147483647; 84 | files = ( 85 | ); 86 | runOnlyForDeploymentPostprocessing = 0; 87 | }; 88 | /* End PBXFrameworksBuildPhase section */ 89 | 90 | /* Begin PBXGroup section */ 91 | 8456B9361E541D90001FC4C8 /* WQLog */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 84832E231E6CFAC900C48F26 /* WQLog.h */, 95 | 84832E241E6CFAC900C48F26 /* WQLog.m */, 96 | ); 97 | path = WQLog; 98 | sourceTree = ""; 99 | }; 100 | 84CF0BC81E5294FE001FF383 = { 101 | isa = PBXGroup; 102 | children = ( 103 | 84CF0BD31E5294FE001FF383 /* WQPermissionRequest */, 104 | 84CF0BED1E5294FE001FF383 /* WQPermissionRequestTests */, 105 | 84CF0BF81E5294FE001FF383 /* WQPermissionRequestUITests */, 106 | 84CF0BD21E5294FE001FF383 /* Products */, 107 | ); 108 | sourceTree = ""; 109 | }; 110 | 84CF0BD21E5294FE001FF383 /* Products */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 84CF0BD11E5294FE001FF383 /* WQPermissionRequest.app */, 114 | 84CF0BEA1E5294FE001FF383 /* WQPermissionRequestTests.xctest */, 115 | 84CF0BF51E5294FE001FF383 /* WQPermissionRequestUITests.xctest */, 116 | ); 117 | name = Products; 118 | sourceTree = ""; 119 | }; 120 | 84CF0BD31E5294FE001FF383 /* WQPermissionRequest */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 8456B93A1E541DA0001FC4C8 /* PrefixHeader.pch */, 124 | 8456B9361E541D90001FC4C8 /* WQLog */, 125 | 84CF0C071E52951A001FF383 /* WQPermissionRequest */, 126 | 84CF0BD71E5294FE001FF383 /* AppDelegate.h */, 127 | 84CF0BD81E5294FE001FF383 /* AppDelegate.m */, 128 | 84CF0BDA1E5294FE001FF383 /* ViewController.h */, 129 | 84CF0BDB1E5294FE001FF383 /* ViewController.m */, 130 | 84CF0BDD1E5294FE001FF383 /* Main.storyboard */, 131 | 84CF0BE01E5294FE001FF383 /* Assets.xcassets */, 132 | 84CF0BE21E5294FE001FF383 /* LaunchScreen.storyboard */, 133 | 84CF0BE51E5294FE001FF383 /* Info.plist */, 134 | 84CF0BD41E5294FE001FF383 /* Supporting Files */, 135 | ); 136 | path = WQPermissionRequest; 137 | sourceTree = ""; 138 | }; 139 | 84CF0BD41E5294FE001FF383 /* Supporting Files */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 84CF0BD51E5294FE001FF383 /* main.m */, 143 | ); 144 | name = "Supporting Files"; 145 | sourceTree = ""; 146 | }; 147 | 84CF0BED1E5294FE001FF383 /* WQPermissionRequestTests */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | 84CF0BEE1E5294FE001FF383 /* WQPermissionRequestTests.m */, 151 | 84CF0BF01E5294FE001FF383 /* Info.plist */, 152 | ); 153 | path = WQPermissionRequestTests; 154 | sourceTree = ""; 155 | }; 156 | 84CF0BF81E5294FE001FF383 /* WQPermissionRequestUITests */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | 84CF0BF91E5294FE001FF383 /* WQPermissionRequestUITests.m */, 160 | 84CF0BFB1E5294FE001FF383 /* Info.plist */, 161 | ); 162 | path = WQPermissionRequestUITests; 163 | sourceTree = ""; 164 | }; 165 | 84CF0C071E52951A001FF383 /* WQPermissionRequest */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 84CF0C081E52959C001FF383 /* WQPermissionRequest.h */, 169 | 84CF0C091E52959C001FF383 /* WQPermissionRequest.m */, 170 | 84CF0C131E52EBE2001FF383 /* WQLocalized.strings */, 171 | ); 172 | path = WQPermissionRequest; 173 | sourceTree = ""; 174 | }; 175 | /* End PBXGroup section */ 176 | 177 | /* Begin PBXNativeTarget section */ 178 | 84CF0BD01E5294FE001FF383 /* WQPermissionRequest */ = { 179 | isa = PBXNativeTarget; 180 | buildConfigurationList = 84CF0BFE1E5294FE001FF383 /* Build configuration list for PBXNativeTarget "WQPermissionRequest" */; 181 | buildPhases = ( 182 | 84CF0BCD1E5294FE001FF383 /* Sources */, 183 | 84CF0BCE1E5294FE001FF383 /* Frameworks */, 184 | 84CF0BCF1E5294FE001FF383 /* Resources */, 185 | ); 186 | buildRules = ( 187 | ); 188 | dependencies = ( 189 | ); 190 | name = WQPermissionRequest; 191 | productName = WQPermissionRequest; 192 | productReference = 84CF0BD11E5294FE001FF383 /* WQPermissionRequest.app */; 193 | productType = "com.apple.product-type.application"; 194 | }; 195 | 84CF0BE91E5294FE001FF383 /* WQPermissionRequestTests */ = { 196 | isa = PBXNativeTarget; 197 | buildConfigurationList = 84CF0C011E5294FE001FF383 /* Build configuration list for PBXNativeTarget "WQPermissionRequestTests" */; 198 | buildPhases = ( 199 | 84CF0BE61E5294FE001FF383 /* Sources */, 200 | 84CF0BE71E5294FE001FF383 /* Frameworks */, 201 | 84CF0BE81E5294FE001FF383 /* Resources */, 202 | ); 203 | buildRules = ( 204 | ); 205 | dependencies = ( 206 | 84CF0BEC1E5294FE001FF383 /* PBXTargetDependency */, 207 | ); 208 | name = WQPermissionRequestTests; 209 | productName = WQPermissionRequestTests; 210 | productReference = 84CF0BEA1E5294FE001FF383 /* WQPermissionRequestTests.xctest */; 211 | productType = "com.apple.product-type.bundle.unit-test"; 212 | }; 213 | 84CF0BF41E5294FE001FF383 /* WQPermissionRequestUITests */ = { 214 | isa = PBXNativeTarget; 215 | buildConfigurationList = 84CF0C041E5294FE001FF383 /* Build configuration list for PBXNativeTarget "WQPermissionRequestUITests" */; 216 | buildPhases = ( 217 | 84CF0BF11E5294FE001FF383 /* Sources */, 218 | 84CF0BF21E5294FE001FF383 /* Frameworks */, 219 | 84CF0BF31E5294FE001FF383 /* Resources */, 220 | ); 221 | buildRules = ( 222 | ); 223 | dependencies = ( 224 | 84CF0BF71E5294FE001FF383 /* PBXTargetDependency */, 225 | ); 226 | name = WQPermissionRequestUITests; 227 | productName = WQPermissionRequestUITests; 228 | productReference = 84CF0BF51E5294FE001FF383 /* WQPermissionRequestUITests.xctest */; 229 | productType = "com.apple.product-type.bundle.ui-testing"; 230 | }; 231 | /* End PBXNativeTarget section */ 232 | 233 | /* Begin PBXProject section */ 234 | 84CF0BC91E5294FE001FF383 /* Project object */ = { 235 | isa = PBXProject; 236 | attributes = { 237 | LastUpgradeCheck = 0720; 238 | ORGANIZATIONNAME = jolimark; 239 | TargetAttributes = { 240 | 84CF0BD01E5294FE001FF383 = { 241 | CreatedOnToolsVersion = 7.2; 242 | DevelopmentTeam = 34CX627AKS; 243 | SystemCapabilities = { 244 | com.apple.BackgroundModes = { 245 | enabled = 1; 246 | }; 247 | }; 248 | }; 249 | 84CF0BE91E5294FE001FF383 = { 250 | CreatedOnToolsVersion = 7.2; 251 | TestTargetID = 84CF0BD01E5294FE001FF383; 252 | }; 253 | 84CF0BF41E5294FE001FF383 = { 254 | CreatedOnToolsVersion = 7.2; 255 | TestTargetID = 84CF0BD01E5294FE001FF383; 256 | }; 257 | }; 258 | }; 259 | buildConfigurationList = 84CF0BCC1E5294FE001FF383 /* Build configuration list for PBXProject "WQPermissionRequest" */; 260 | compatibilityVersion = "Xcode 3.2"; 261 | developmentRegion = English; 262 | hasScannedForEncodings = 0; 263 | knownRegions = ( 264 | en, 265 | Base, 266 | ); 267 | mainGroup = 84CF0BC81E5294FE001FF383; 268 | productRefGroup = 84CF0BD21E5294FE001FF383 /* Products */; 269 | projectDirPath = ""; 270 | projectRoot = ""; 271 | targets = ( 272 | 84CF0BD01E5294FE001FF383 /* WQPermissionRequest */, 273 | 84CF0BE91E5294FE001FF383 /* WQPermissionRequestTests */, 274 | 84CF0BF41E5294FE001FF383 /* WQPermissionRequestUITests */, 275 | ); 276 | }; 277 | /* End PBXProject section */ 278 | 279 | /* Begin PBXResourcesBuildPhase section */ 280 | 84CF0BCF1E5294FE001FF383 /* Resources */ = { 281 | isa = PBXResourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | 84CF0BE41E5294FE001FF383 /* LaunchScreen.storyboard in Resources */, 285 | 84CF0BE11E5294FE001FF383 /* Assets.xcassets in Resources */, 286 | 84CF0C111E52EBE2001FF383 /* WQLocalized.strings in Resources */, 287 | 84CF0BDF1E5294FE001FF383 /* Main.storyboard in Resources */, 288 | ); 289 | runOnlyForDeploymentPostprocessing = 0; 290 | }; 291 | 84CF0BE81E5294FE001FF383 /* Resources */ = { 292 | isa = PBXResourcesBuildPhase; 293 | buildActionMask = 2147483647; 294 | files = ( 295 | ); 296 | runOnlyForDeploymentPostprocessing = 0; 297 | }; 298 | 84CF0BF31E5294FE001FF383 /* Resources */ = { 299 | isa = PBXResourcesBuildPhase; 300 | buildActionMask = 2147483647; 301 | files = ( 302 | ); 303 | runOnlyForDeploymentPostprocessing = 0; 304 | }; 305 | /* End PBXResourcesBuildPhase section */ 306 | 307 | /* Begin PBXSourcesBuildPhase section */ 308 | 84CF0BCD1E5294FE001FF383 /* Sources */ = { 309 | isa = PBXSourcesBuildPhase; 310 | buildActionMask = 2147483647; 311 | files = ( 312 | 84CF0BDC1E5294FE001FF383 /* ViewController.m in Sources */, 313 | 84CF0BD91E5294FE001FF383 /* AppDelegate.m in Sources */, 314 | 84CF0C0A1E52959C001FF383 /* WQPermissionRequest.m in Sources */, 315 | 84832E251E6CFAC900C48F26 /* WQLog.m in Sources */, 316 | 84CF0BD61E5294FE001FF383 /* main.m in Sources */, 317 | ); 318 | runOnlyForDeploymentPostprocessing = 0; 319 | }; 320 | 84CF0BE61E5294FE001FF383 /* Sources */ = { 321 | isa = PBXSourcesBuildPhase; 322 | buildActionMask = 2147483647; 323 | files = ( 324 | 84CF0BEF1E5294FE001FF383 /* WQPermissionRequestTests.m in Sources */, 325 | ); 326 | runOnlyForDeploymentPostprocessing = 0; 327 | }; 328 | 84CF0BF11E5294FE001FF383 /* Sources */ = { 329 | isa = PBXSourcesBuildPhase; 330 | buildActionMask = 2147483647; 331 | files = ( 332 | 84CF0BFA1E5294FE001FF383 /* WQPermissionRequestUITests.m in Sources */, 333 | ); 334 | runOnlyForDeploymentPostprocessing = 0; 335 | }; 336 | /* End PBXSourcesBuildPhase section */ 337 | 338 | /* Begin PBXTargetDependency section */ 339 | 84CF0BEC1E5294FE001FF383 /* PBXTargetDependency */ = { 340 | isa = PBXTargetDependency; 341 | target = 84CF0BD01E5294FE001FF383 /* WQPermissionRequest */; 342 | targetProxy = 84CF0BEB1E5294FE001FF383 /* PBXContainerItemProxy */; 343 | }; 344 | 84CF0BF71E5294FE001FF383 /* PBXTargetDependency */ = { 345 | isa = PBXTargetDependency; 346 | target = 84CF0BD01E5294FE001FF383 /* WQPermissionRequest */; 347 | targetProxy = 84CF0BF61E5294FE001FF383 /* PBXContainerItemProxy */; 348 | }; 349 | /* End PBXTargetDependency section */ 350 | 351 | /* Begin PBXVariantGroup section */ 352 | 84CF0BDD1E5294FE001FF383 /* Main.storyboard */ = { 353 | isa = PBXVariantGroup; 354 | children = ( 355 | 84CF0BDE1E5294FE001FF383 /* Base */, 356 | ); 357 | name = Main.storyboard; 358 | sourceTree = ""; 359 | }; 360 | 84CF0BE21E5294FE001FF383 /* LaunchScreen.storyboard */ = { 361 | isa = PBXVariantGroup; 362 | children = ( 363 | 84CF0BE31E5294FE001FF383 /* Base */, 364 | ); 365 | name = LaunchScreen.storyboard; 366 | sourceTree = ""; 367 | }; 368 | 84CF0C131E52EBE2001FF383 /* WQLocalized.strings */ = { 369 | isa = PBXVariantGroup; 370 | children = ( 371 | 84CF0C121E52EBE2001FF383 /* Base */, 372 | 84CF0C141E52EBE3001FF383 /* en */, 373 | ); 374 | name = WQLocalized.strings; 375 | sourceTree = ""; 376 | }; 377 | /* End PBXVariantGroup section */ 378 | 379 | /* Begin XCBuildConfiguration section */ 380 | 84CF0BFC1E5294FE001FF383 /* Debug */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ALWAYS_SEARCH_USER_PATHS = NO; 384 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 385 | CLANG_CXX_LIBRARY = "libc++"; 386 | CLANG_ENABLE_MODULES = YES; 387 | CLANG_ENABLE_OBJC_ARC = YES; 388 | CLANG_WARN_BOOL_CONVERSION = YES; 389 | CLANG_WARN_CONSTANT_CONVERSION = YES; 390 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 391 | CLANG_WARN_EMPTY_BODY = YES; 392 | CLANG_WARN_ENUM_CONVERSION = YES; 393 | CLANG_WARN_INT_CONVERSION = YES; 394 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 395 | CLANG_WARN_UNREACHABLE_CODE = YES; 396 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 397 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 398 | COPY_PHASE_STRIP = NO; 399 | DEBUG_INFORMATION_FORMAT = dwarf; 400 | ENABLE_STRICT_OBJC_MSGSEND = YES; 401 | ENABLE_TESTABILITY = YES; 402 | GCC_C_LANGUAGE_STANDARD = gnu99; 403 | GCC_DYNAMIC_NO_PIC = NO; 404 | GCC_NO_COMMON_BLOCKS = YES; 405 | GCC_OPTIMIZATION_LEVEL = 0; 406 | GCC_PREPROCESSOR_DEFINITIONS = ( 407 | "DEBUG=1", 408 | "$(inherited)", 409 | ); 410 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 411 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 412 | GCC_WARN_UNDECLARED_SELECTOR = YES; 413 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 414 | GCC_WARN_UNUSED_FUNCTION = YES; 415 | GCC_WARN_UNUSED_VARIABLE = YES; 416 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 417 | MTL_ENABLE_DEBUG_INFO = YES; 418 | ONLY_ACTIVE_ARCH = YES; 419 | SDKROOT = iphoneos; 420 | }; 421 | name = Debug; 422 | }; 423 | 84CF0BFD1E5294FE001FF383 /* Release */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | ALWAYS_SEARCH_USER_PATHS = NO; 427 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 428 | CLANG_CXX_LIBRARY = "libc++"; 429 | CLANG_ENABLE_MODULES = YES; 430 | CLANG_ENABLE_OBJC_ARC = YES; 431 | CLANG_WARN_BOOL_CONVERSION = YES; 432 | CLANG_WARN_CONSTANT_CONVERSION = YES; 433 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 434 | CLANG_WARN_EMPTY_BODY = YES; 435 | CLANG_WARN_ENUM_CONVERSION = YES; 436 | CLANG_WARN_INT_CONVERSION = YES; 437 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 438 | CLANG_WARN_UNREACHABLE_CODE = YES; 439 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 440 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 441 | COPY_PHASE_STRIP = NO; 442 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 443 | ENABLE_NS_ASSERTIONS = NO; 444 | ENABLE_STRICT_OBJC_MSGSEND = YES; 445 | GCC_C_LANGUAGE_STANDARD = gnu99; 446 | GCC_NO_COMMON_BLOCKS = YES; 447 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 448 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 449 | GCC_WARN_UNDECLARED_SELECTOR = YES; 450 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 451 | GCC_WARN_UNUSED_FUNCTION = YES; 452 | GCC_WARN_UNUSED_VARIABLE = YES; 453 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 454 | MTL_ENABLE_DEBUG_INFO = NO; 455 | SDKROOT = iphoneos; 456 | VALIDATE_PRODUCT = YES; 457 | }; 458 | name = Release; 459 | }; 460 | 84CF0BFF1E5294FE001FF383 /* Debug */ = { 461 | isa = XCBuildConfiguration; 462 | buildSettings = { 463 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 464 | DEVELOPMENT_TEAM = 34CX627AKS; 465 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 466 | GCC_PREFIX_HEADER = "${PROJECT_NAME}/PrefixHeader.pch"; 467 | INFOPLIST_FILE = WQPermissionRequest/Info.plist; 468 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 469 | PRODUCT_BUNDLE_IDENTIFIER = cn.com.Auxdio.WQPermissionRequest; 470 | PRODUCT_NAME = "$(TARGET_NAME)"; 471 | }; 472 | name = Debug; 473 | }; 474 | 84CF0C001E5294FE001FF383 /* Release */ = { 475 | isa = XCBuildConfiguration; 476 | buildSettings = { 477 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 478 | DEVELOPMENT_TEAM = 34CX627AKS; 479 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 480 | GCC_PREFIX_HEADER = "${PROJECT_NAME}/PrefixHeader.pch"; 481 | INFOPLIST_FILE = WQPermissionRequest/Info.plist; 482 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 483 | PRODUCT_BUNDLE_IDENTIFIER = cn.com.Auxdio.WQPermissionRequest; 484 | PRODUCT_NAME = "$(TARGET_NAME)"; 485 | }; 486 | name = Release; 487 | }; 488 | 84CF0C021E5294FE001FF383 /* Debug */ = { 489 | isa = XCBuildConfiguration; 490 | buildSettings = { 491 | BUNDLE_LOADER = "$(TEST_HOST)"; 492 | INFOPLIST_FILE = WQPermissionRequestTests/Info.plist; 493 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 494 | PRODUCT_BUNDLE_IDENTIFIER = com.jolimark.www.WQPermissionRequestTests; 495 | PRODUCT_NAME = "$(TARGET_NAME)"; 496 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WQPermissionRequest.app/WQPermissionRequest"; 497 | }; 498 | name = Debug; 499 | }; 500 | 84CF0C031E5294FE001FF383 /* Release */ = { 501 | isa = XCBuildConfiguration; 502 | buildSettings = { 503 | BUNDLE_LOADER = "$(TEST_HOST)"; 504 | INFOPLIST_FILE = WQPermissionRequestTests/Info.plist; 505 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 506 | PRODUCT_BUNDLE_IDENTIFIER = com.jolimark.www.WQPermissionRequestTests; 507 | PRODUCT_NAME = "$(TARGET_NAME)"; 508 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WQPermissionRequest.app/WQPermissionRequest"; 509 | }; 510 | name = Release; 511 | }; 512 | 84CF0C051E5294FE001FF383 /* Debug */ = { 513 | isa = XCBuildConfiguration; 514 | buildSettings = { 515 | INFOPLIST_FILE = WQPermissionRequestUITests/Info.plist; 516 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 517 | PRODUCT_BUNDLE_IDENTIFIER = com.jolimark.www.WQPermissionRequestUITests; 518 | PRODUCT_NAME = "$(TARGET_NAME)"; 519 | TEST_TARGET_NAME = WQPermissionRequest; 520 | USES_XCTRUNNER = YES; 521 | }; 522 | name = Debug; 523 | }; 524 | 84CF0C061E5294FE001FF383 /* Release */ = { 525 | isa = XCBuildConfiguration; 526 | buildSettings = { 527 | INFOPLIST_FILE = WQPermissionRequestUITests/Info.plist; 528 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 529 | PRODUCT_BUNDLE_IDENTIFIER = com.jolimark.www.WQPermissionRequestUITests; 530 | PRODUCT_NAME = "$(TARGET_NAME)"; 531 | TEST_TARGET_NAME = WQPermissionRequest; 532 | USES_XCTRUNNER = YES; 533 | }; 534 | name = Release; 535 | }; 536 | /* End XCBuildConfiguration section */ 537 | 538 | /* Begin XCConfigurationList section */ 539 | 84CF0BCC1E5294FE001FF383 /* Build configuration list for PBXProject "WQPermissionRequest" */ = { 540 | isa = XCConfigurationList; 541 | buildConfigurations = ( 542 | 84CF0BFC1E5294FE001FF383 /* Debug */, 543 | 84CF0BFD1E5294FE001FF383 /* Release */, 544 | ); 545 | defaultConfigurationIsVisible = 0; 546 | defaultConfigurationName = Release; 547 | }; 548 | 84CF0BFE1E5294FE001FF383 /* Build configuration list for PBXNativeTarget "WQPermissionRequest" */ = { 549 | isa = XCConfigurationList; 550 | buildConfigurations = ( 551 | 84CF0BFF1E5294FE001FF383 /* Debug */, 552 | 84CF0C001E5294FE001FF383 /* Release */, 553 | ); 554 | defaultConfigurationIsVisible = 0; 555 | defaultConfigurationName = Release; 556 | }; 557 | 84CF0C011E5294FE001FF383 /* Build configuration list for PBXNativeTarget "WQPermissionRequestTests" */ = { 558 | isa = XCConfigurationList; 559 | buildConfigurations = ( 560 | 84CF0C021E5294FE001FF383 /* Debug */, 561 | 84CF0C031E5294FE001FF383 /* Release */, 562 | ); 563 | defaultConfigurationIsVisible = 0; 564 | defaultConfigurationName = Release; 565 | }; 566 | 84CF0C041E5294FE001FF383 /* Build configuration list for PBXNativeTarget "WQPermissionRequestUITests" */ = { 567 | isa = XCConfigurationList; 568 | buildConfigurations = ( 569 | 84CF0C051E5294FE001FF383 /* Debug */, 570 | 84CF0C061E5294FE001FF383 /* Release */, 571 | ); 572 | defaultConfigurationIsVisible = 0; 573 | defaultConfigurationName = Release; 574 | }; 575 | /* End XCConfigurationList section */ 576 | }; 577 | rootObject = 84CF0BC91E5294FE001FF383 /* Project object */; 578 | } 579 | -------------------------------------------------------------------------------- /WQPermissionRequest/WQPermissionRequest/WQPermissionRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // WQPermissionRequest.m 3 | // WQPermissionRequest 4 | // 5 | // Created by admin on 17/2/14. 6 | // Copyright © 2017年 jolimark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | #import 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | 21 | #import "WQPermissionRequest.h" 22 | 23 | typedef enum { 24 | WQAuthorizationStatusNotDetermined, // 第一次请求授权 25 | WQAuthorizationStatusAuthorized, // 已经授权成功 26 | WQAuthorizationStatusForbid // 非第一次请求授权 27 | }WQPermissionAuthorizationStatus; 28 | 29 | @interface WQPermissionRequest () 30 | < 31 | CLLocationManagerDelegate 32 | > 33 | @property (nonatomic, strong) CLLocationManager *manager; 34 | @property (nonatomic, copy, nullable) WQRequestResult locationResult; 35 | @end 36 | 37 | @implementation WQPermissionRequest 38 | + (instancetype)allocWithZone:(struct _NSZone *)zone { 39 | @synchronized(self) { 40 | if (shareRequest == nil) { 41 | shareRequest = [super allocWithZone:zone]; 42 | } 43 | } 44 | return shareRequest; 45 | } 46 | 47 | static WQPermissionRequest *shareRequest; 48 | + (WQPermissionRequest *)shareWQPermissionRequest { 49 | @synchronized(self) { 50 | if (shareRequest == nil) { 51 | shareRequest = [[self alloc] init]; 52 | } 53 | } 54 | return shareRequest; 55 | } 56 | 57 | - (instancetype)init { 58 | if (self = [super init]) { 59 | } 60 | return self; 61 | } 62 | 63 | - (UIViewController *)currentViewController { 64 | UIViewController *result = nil; UIWindow * window = [[UIApplication sharedApplication] keyWindow]; 65 | 66 | //app默认windowLevel是UIWindowLevelNormal,如果不是,找到UIWindowLevelNormal的 67 | if (window.windowLevel != UIWindowLevelNormal) { 68 | NSArray *windows = [[UIApplication sharedApplication] windows]; 69 | for(UIWindow * tmpWin in windows) { 70 | if (tmpWin.windowLevel == UIWindowLevelNormal) { 71 | window = tmpWin; break; 72 | } 73 | } 74 | } 75 | id nextResponder = nil; 76 | UIViewController *appRootVC=window.rootViewController; 77 | 78 | // 如果是present上来的appRootVC.presentedViewController 不为nil 79 | if (appRootVC.presentedViewController) { 80 | nextResponder = appRootVC.presentedViewController; 81 | }else{ 82 | UIView *frontView = [[window subviews] objectAtIndex:0]; 83 | nextResponder = [frontView nextResponder]; 84 | } 85 | if ([nextResponder isKindOfClass:[UITabBarController class]]){ 86 | UITabBarController * tabbar = (UITabBarController *)nextResponder; 87 | UINavigationController * nav = (UINavigationController *)tabbar.viewControllers[tabbar.selectedIndex]; 88 | // 上下两种写法都行 UINavigationController * nav = tabbar.selectedViewController; 89 | result=nav.childViewControllers.lastObject; 90 | }else if ([nextResponder isKindOfClass:[UINavigationController class]]){ 91 | UIViewController * nav = (UIViewController *)nextResponder; 92 | result = nav.childViewControllers.lastObject; 93 | }else{ 94 | result = nextResponder; 95 | } 96 | return result; 97 | } 98 | 99 | - (BOOL)determinePermission:(WQPermission)permission { 100 | WQPermissionAuthorizationStatus determine = [self authorizationPermission:permission]; 101 | return determine == WQAuthorizationStatusAuthorized; 102 | } 103 | 104 | - (void)requestPermission:(WQPermission)permission 105 | title:(NSString *)title 106 | description:(NSString *)description 107 | requestResult:(WQRequestResult)result { 108 | WQPermissionAuthorizationStatus authorization = [self authorizationPermission:permission]; 109 | if (result == nil) { 110 | result = ^(BOOL granted, NSError *error) { 111 | };; 112 | } 113 | switch (authorization) { 114 | case WQAuthorizationStatusNotDetermined: 115 | // 第一次请求 116 | [self requestPermission:permission 117 | requestResult:result]; 118 | return; 119 | break; 120 | case WQAuthorizationStatusForbid: 121 | // 之前请求过,现在禁了权限 122 | WQLogInf(@"之前请求过,现在禁了权限"); 123 | self.locationResult = (permission == WQLocationAllows) || 124 | (permission == WQLocationWhenInUse) ? result : nil; 125 | break; 126 | case WQAuthorizationStatusAuthorized: 127 | // 已经授权 128 | WQLogMes(@"已经授权"); 129 | result(YES, nil); 130 | return; 131 | break; 132 | } 133 | __weak typeof(self) weakSelf = self; 134 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:title 135 | message:description 136 | preferredStyle:UIAlertControllerStyleAlert]; 137 | UIAlertAction *setting = [UIAlertAction actionWithTitle:WQLocalized(@"Setting") 138 | style:UIAlertActionStyleDefault 139 | handler:^(UIAlertAction * _Nonnull action) { 140 | dispatch_async(dispatch_get_main_queue(), ^{ 141 | NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; 142 | if([[UIApplication sharedApplication] canOpenURL:url]) { 143 | NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString]; 144 | [[UIApplication sharedApplication] openURL:url]; 145 | } 146 | }); 147 | }]; 148 | UIAlertAction *dontAllows = [UIAlertAction actionWithTitle:WQLocalized(@"Don't Allow") 149 | style:UIAlertActionStyleDestructive 150 | handler:^(UIAlertAction * _Nonnull action) { 151 | NSError *error = [NSError errorWithDomain:WQErrorDomain 152 | code:WQForbidPermission 153 | userInfo:@{NSLocalizedDescriptionKey : WQLocalized(@"Forbid permission")}]; 154 | result(NO,error); 155 | weakSelf.locationResult = nil; 156 | }]; 157 | [alert addAction:setting]; 158 | [alert addAction:dontAllows]; 159 | UIViewController *currentVC = [self currentViewController]; 160 | [currentVC presentViewController:alert 161 | animated:YES 162 | completion:nil]; 163 | } 164 | 165 | 166 | /**************************************** 权 限 请 求 ****************************************/ 167 | - (void)requestPermission:(WQPermission)permission 168 | requestResult:(WQRequestResult)result{ 169 | switch (permission) { 170 | case WQCamera:{ 171 | [self requestCamera:result]; 172 | break; 173 | } 174 | case WQLocationAllows:{ 175 | [self requestLocationAllows:result]; 176 | break; 177 | } 178 | case WQLocationWhenInUse:{ 179 | [self requestLocationWhenInUse:result]; 180 | break; 181 | } 182 | case WQCalendars:{ 183 | [self requestCalendars:result]; 184 | break; 185 | } 186 | case WQReminders:{ 187 | [self requestReminders:result]; 188 | break; 189 | } 190 | case WQUserNotification:{ 191 | [self requestUserNotification:result]; 192 | break; 193 | } 194 | case WQPhotoLibrary:{ 195 | [self requestPhotoLibrary:result]; 196 | break; 197 | } 198 | case WQMicrophone:{ 199 | [self requestMicrophone:result]; 200 | break; 201 | } 202 | case WQHealth:{ 203 | [self requestHealth:result]; 204 | break; 205 | } 206 | case WQContacts:{ 207 | [self requestContacts:result]; 208 | break; 209 | } 210 | case WQNetwork:{ 211 | [self requestNetwork:result]; 212 | break; 213 | } 214 | } 215 | } 216 | 217 | - (void)requestCamera:(WQRequestResult)result { 218 | [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo 219 | completionHandler:^(BOOL granted) { 220 | NSError *error; 221 | if (granted) { 222 | WQLogMes(@"开启成功"); 223 | }else { 224 | WQLogErr(@"开启失败"); 225 | error = [NSError errorWithDomain:WQErrorDomain 226 | code:WQFailueAuthorize 227 | userInfo:@{NSLocalizedDescriptionKey : WQLocalized(@"Failue authorize")}]; 228 | } 229 | result(granted, error); 230 | }]; 231 | } 232 | 233 | - (void)requestLocationAllows:(WQRequestResult)result { 234 | if (!self.manager) { 235 | self.manager = [[CLLocationManager alloc] init]; 236 | self.manager.delegate = self; 237 | } 238 | self.locationResult = result; 239 | [self.manager requestAlwaysAuthorization]; 240 | } 241 | 242 | - (void)requestLocationWhenInUse:(WQRequestResult)result { 243 | if (!self.manager) { 244 | self.manager = [[CLLocationManager alloc] init]; 245 | self.manager.delegate = self; 246 | } 247 | self.locationResult = result; 248 | [self.manager requestWhenInUseAuthorization]; 249 | } 250 | 251 | - (void)requestCalendars:(WQRequestResult)result { 252 | EKEventStore *store = [[EKEventStore alloc] init]; 253 | [store requestAccessToEntityType:EKEntityTypeEvent 254 | completion:^(BOOL granted, 255 | NSError * _Nullable error) { 256 | if (error) { 257 | WQLogErr(@"error: %@",error); 258 | }else { 259 | if (granted) { 260 | WQLogMes(@"请求成功"); 261 | }else { 262 | WQLogErr(@"请求失败"); 263 | } 264 | } 265 | result(granted, error); 266 | }]; 267 | } 268 | 269 | - (void)requestReminders:(WQRequestResult)result { 270 | EKEventStore *store = [[EKEventStore alloc] init]; 271 | [store requestAccessToEntityType:EKEntityTypeReminder 272 | completion:^(BOOL granted, 273 | NSError * _Nullable error) { 274 | if (error) { 275 | WQLogErr(@"error: %@",error); 276 | }else { 277 | if (granted) { 278 | WQLogMes(@"请求成功"); 279 | }else { 280 | WQLogErr(@"请求失败"); 281 | } 282 | } 283 | result(granted, error); 284 | }]; 285 | } 286 | 287 | - (void)requestUserNotification:(WQRequestResult)result { 288 | UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes: 289 | UIUserNotificationTypeSound | 290 | UIUserNotificationTypeAlert | 291 | UIUserNotificationTypeBadge 292 | categories:nil]; 293 | [[UIApplication sharedApplication] registerUserNotificationSettings:setting]; 294 | } 295 | 296 | - (void)requestPhotoLibrary:(WQRequestResult)result { 297 | if ([[UIDevice currentDevice].systemVersion floatValue] > 8.0) { 298 | [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 299 | NSError *error; 300 | BOOL granted = NO; 301 | if (status == PHAuthorizationStatusAuthorized) { 302 | WQLogMes(@"授权成功"); 303 | granted = YES; 304 | }else { 305 | WQLogErr(@"授权失败"); 306 | error = [NSError errorWithDomain:WQErrorDomain 307 | code:WQFailueAuthorize 308 | userInfo:@{NSLocalizedDescriptionKey : WQLocalized(@"Failue authorize")}]; 309 | } 310 | result(granted, error); 311 | }]; 312 | } 313 | } 314 | 315 | - (void)requestMicrophone:(WQRequestResult)result { 316 | AVAudioSession *session = [AVAudioSession sharedInstance]; 317 | [session requestRecordPermission:^(BOOL granted) { 318 | NSError *error; 319 | if (granted) { 320 | WQLogMes(@"请求成功"); 321 | }else { 322 | WQLogErr(@"请求失败"); 323 | error = [NSError errorWithDomain:WQErrorDomain 324 | code:WQFailueAuthorize 325 | userInfo:@{NSLocalizedDescriptionKey : WQLocalized(@"Failue authorize")}]; 326 | } 327 | result(granted, error); 328 | }]; 329 | } 330 | 331 | - (void)requestHealth:(WQRequestResult)result { 332 | if (![HKHealthStore isHealthDataAvailable]) { 333 | WQLogErr(@"不支持 Health"); 334 | NSError *error = [NSError errorWithDomain:WQErrorDomain 335 | code:WQUnsuportAuthorize 336 | userInfo:@{NSLocalizedDescriptionKey : WQLocalized(@"Unsuport authorize")}]; 337 | result(NO, error); 338 | return; 339 | } 340 | HKHealthStore *healthStore = [[HKHealthStore alloc] init]; 341 | // Share body mass, height and body mass index 342 | NSSet *shareObjectTypes = [NSSet setWithObjects: 343 | [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass], 344 | [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight], 345 | [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex], 346 | nil]; 347 | // Read date of birth, biological sex and step count 348 | NSSet *readObjectTypes = [NSSet setWithObjects: 349 | [HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth], 350 | [HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBiologicalSex], 351 | [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount], 352 | nil]; 353 | // Request access 354 | [healthStore requestAuthorizationToShareTypes:shareObjectTypes 355 | readTypes:readObjectTypes 356 | completion:^(BOOL success, 357 | NSError *error) { 358 | if (error) { 359 | WQLogErr(@"error: %@",error); 360 | }else { 361 | if(success == YES){ 362 | WQLogMes(@"请求成功"); 363 | } 364 | else{ 365 | WQLogErr(@"请求失败"); 366 | } 367 | } 368 | result(success, error); 369 | }]; 370 | } 371 | 372 | - (void)requestContacts:(WQRequestResult)result { 373 | if ([[[UIDevice currentDevice] systemVersion] floatValue] > 9.0) { 374 | CNContactStore *store = [[CNContactStore alloc] init]; 375 | [store requestAccessForEntityType:CNEntityTypeContacts 376 | completionHandler:^(BOOL granted, 377 | NSError * _Nullable error) { 378 | if (error) { 379 | WQLogErr(@"error: %@",error); 380 | }else { 381 | if (granted) { 382 | WQLogMes(@"请求成功"); 383 | }else { 384 | WQLogErr(@"请求失败"); 385 | } 386 | } 387 | result(granted, error); 388 | }]; 389 | }else { 390 | ABAddressBookRef addressBook = ABAddressBookCreate(); 391 | ABAddressBookRequestAccessWithCompletion(addressBook, 392 | ^(bool granted, 393 | CFErrorRef error) { 394 | if (error) { 395 | WQLogErr(@"error: %@",error); 396 | }else { 397 | if (granted) { 398 | WQLogMes(@"请求成功"); 399 | }else { 400 | WQLogErr(@"请求失败"); 401 | } 402 | } 403 | result(granted, (__bridge NSError *)(error)); 404 | }); 405 | } 406 | } 407 | 408 | - (void)requestNetwork:(WQRequestResult)result { 409 | NSAssert(0, @"* * * * * * 网络手动授权还未实现 * * * * * *"); 410 | } 411 | 412 | 413 | 414 | /**************************************** 权 限 判 断 ****************************************/ 415 | - (WQPermissionAuthorizationStatus)authorizationPermission:(WQPermission)permission { 416 | WQPermissionAuthorizationStatus authorization; 417 | switch (permission) { 418 | case WQCamera: 419 | authorization = [self determineCamera]; 420 | break; 421 | case WQLocationAllows: 422 | authorization = [self determineLocationAllows]; 423 | break; 424 | case WQLocationWhenInUse: 425 | authorization = [self determineLocationWhenInUse]; 426 | break; 427 | case WQCalendars: 428 | authorization = [self determineCalendars]; 429 | break; 430 | case WQReminders: 431 | authorization = [self determineReminders]; 432 | break; 433 | case WQPhotoLibrary: 434 | authorization = [self determinePhotoLibrary]; 435 | break; 436 | case WQUserNotification: 437 | authorization = [self determineUserNotification]; 438 | break; 439 | case WQMicrophone: 440 | authorization = [self determineMicrophone]; 441 | break; 442 | case WQHealth: 443 | authorization = [self determineHealth]; 444 | break; 445 | case WQContacts: 446 | authorization = [self determineContacts]; 447 | break; 448 | case WQNetwork: 449 | authorization = [self determineNetwork]; 450 | break; 451 | } 452 | return authorization; 453 | } 454 | 455 | - (WQPermissionAuthorizationStatus)determineCamera { 456 | AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 457 | switch (authStatus) { 458 | case AVAuthorizationStatusNotDetermined: { 459 | return WQAuthorizationStatusNotDetermined; 460 | break; 461 | } 462 | case AVAuthorizationStatusRestricted: 463 | case AVAuthorizationStatusDenied: { 464 | return WQAuthorizationStatusForbid; 465 | break; 466 | } 467 | case AVAuthorizationStatusAuthorized: { 468 | return WQAuthorizationStatusAuthorized; 469 | break; 470 | } 471 | } 472 | } 473 | 474 | - (WQPermissionAuthorizationStatus)determineLocationAllows { 475 | if (!self.manager) { 476 | self.manager = [[CLLocationManager alloc] init]; 477 | self.manager.delegate = self; 478 | } 479 | CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus]; 480 | switch (authStatus) { 481 | case kCLAuthorizationStatusNotDetermined: { 482 | return WQAuthorizationStatusNotDetermined; 483 | break; 484 | } 485 | case kCLAuthorizationStatusRestricted: 486 | case kCLAuthorizationStatusDenied: { 487 | return WQAuthorizationStatusForbid; 488 | break; 489 | } 490 | case kCLAuthorizationStatusAuthorizedAlways: 491 | case kCLAuthorizationStatusAuthorizedWhenInUse:{ 492 | return WQAuthorizationStatusAuthorized; 493 | break; 494 | } 495 | } 496 | } 497 | 498 | - (WQPermissionAuthorizationStatus)determineLocationWhenInUse { 499 | if (!self.manager) { 500 | self.manager = [[CLLocationManager alloc] init]; 501 | self.manager.delegate = self; 502 | } 503 | CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus]; 504 | switch (authStatus) { 505 | case kCLAuthorizationStatusNotDetermined: { 506 | return WQAuthorizationStatusNotDetermined; 507 | break; 508 | } 509 | case kCLAuthorizationStatusRestricted: 510 | case kCLAuthorizationStatusDenied: { 511 | return WQAuthorizationStatusForbid; 512 | break; 513 | } 514 | case kCLAuthorizationStatusAuthorizedAlways: 515 | case kCLAuthorizationStatusAuthorizedWhenInUse:{ 516 | return WQAuthorizationStatusAuthorized; 517 | break; 518 | } 519 | } 520 | } 521 | 522 | - (WQPermissionAuthorizationStatus)determineCalendars { 523 | EKAuthorizationStatus authStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]; 524 | switch (authStatus) { 525 | case EKAuthorizationStatusNotDetermined: { 526 | return WQAuthorizationStatusNotDetermined; 527 | break; 528 | } 529 | case EKAuthorizationStatusRestricted: 530 | case EKAuthorizationStatusDenied: { 531 | return WQAuthorizationStatusForbid; 532 | break; 533 | } 534 | case EKAuthorizationStatusAuthorized: { 535 | return WQAuthorizationStatusAuthorized; 536 | break; 537 | } 538 | } 539 | } 540 | 541 | - (WQPermissionAuthorizationStatus)determineReminders { 542 | EKAuthorizationStatus authStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]; 543 | switch (authStatus) { 544 | case EKAuthorizationStatusNotDetermined: { 545 | return WQAuthorizationStatusNotDetermined; 546 | break; 547 | } 548 | case EKAuthorizationStatusRestricted: 549 | case EKAuthorizationStatusDenied: { 550 | return WQAuthorizationStatusForbid; 551 | break; 552 | } 553 | case EKAuthorizationStatusAuthorized: { 554 | return WQAuthorizationStatusAuthorized; 555 | break; 556 | } 557 | } 558 | } 559 | 560 | - (WQPermissionAuthorizationStatus)determinePhotoLibrary { 561 | if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) { 562 | ALAuthorizationStatus authStatus =[ALAssetsLibrary authorizationStatus]; 563 | switch (authStatus) { 564 | case ALAuthorizationStatusNotDetermined: { 565 | return WQAuthorizationStatusNotDetermined; 566 | break; 567 | } 568 | case ALAuthorizationStatusRestricted: 569 | case ALAuthorizationStatusDenied: { 570 | return WQAuthorizationStatusForbid; 571 | break; 572 | } 573 | case ALAuthorizationStatusAuthorized: { 574 | return WQAuthorizationStatusAuthorized; 575 | break; 576 | } 577 | } 578 | } else { 579 | PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus]; 580 | switch (authStatus) { 581 | case PHAuthorizationStatusNotDetermined: { 582 | return WQAuthorizationStatusNotDetermined; 583 | break; 584 | } 585 | case PHAuthorizationStatusRestricted: 586 | case PHAuthorizationStatusDenied: { 587 | return WQAuthorizationStatusForbid; 588 | break; 589 | } 590 | case PHAuthorizationStatusAuthorized: { 591 | return WQAuthorizationStatusAuthorized; 592 | break; 593 | } 594 | } 595 | } 596 | } 597 | 598 | - (WQPermissionAuthorizationStatus)determineUserNotification { 599 | UIUserNotificationType type = [[UIApplication sharedApplication] currentUserNotificationSettings].types; 600 | switch (type) { 601 | case UIUserNotificationTypeNone: { 602 | return WQAuthorizationStatusNotDetermined; 603 | break; 604 | } 605 | case UIUserNotificationTypeBadge: 606 | case UIUserNotificationTypeSound: 607 | case UIUserNotificationTypeAlert: { 608 | return WQAuthorizationStatusAuthorized; 609 | break; 610 | } 611 | } 612 | } 613 | 614 | - (WQPermissionAuthorizationStatus)determineMicrophone { 615 | AVAudioSessionRecordPermission authStatus = [[AVAudioSession sharedInstance] recordPermission]; 616 | switch (authStatus) { 617 | case AVAudioSessionRecordPermissionUndetermined: { 618 | return WQAuthorizationStatusNotDetermined; 619 | break; 620 | } 621 | case AVAudioSessionRecordPermissionDenied: { 622 | return WQAuthorizationStatusForbid; 623 | break; 624 | } 625 | case AVAudioSessionRecordPermissionGranted: { 626 | return WQAuthorizationStatusAuthorized; 627 | break; 628 | } 629 | } 630 | } 631 | 632 | - (WQPermissionAuthorizationStatus)determineHealth { 633 | HKHealthStore *healthStore = [[HKHealthStore alloc] init]; 634 | HKObjectType *hkObjectType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; 635 | HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:hkObjectType]; 636 | switch (authStatus) { 637 | case HKAuthorizationStatusNotDetermined: { 638 | return WQAuthorizationStatusNotDetermined; 639 | break; 640 | } 641 | case HKAuthorizationStatusSharingDenied: { 642 | return WQAuthorizationStatusForbid; 643 | break; 644 | } 645 | case HKAuthorizationStatusSharingAuthorized: { 646 | return WQAuthorizationStatusAuthorized; 647 | break; 648 | } 649 | } 650 | } 651 | 652 | - (WQPermissionAuthorizationStatus)determineContacts { 653 | if ([[[UIDevice currentDevice] systemVersion] floatValue] > 9.0) { 654 | CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; 655 | switch (authStatus) { 656 | case CNAuthorizationStatusNotDetermined: { 657 | return WQAuthorizationStatusNotDetermined; 658 | break; 659 | } 660 | case CNAuthorizationStatusRestricted: 661 | case CNAuthorizationStatusDenied: { 662 | return WQAuthorizationStatusForbid; 663 | break; 664 | } 665 | case CNAuthorizationStatusAuthorized: { 666 | return WQAuthorizationStatusAuthorized; 667 | break; 668 | } 669 | } 670 | }else { 671 | ABAuthorizationStatus authStatus = ABAddressBookGetAuthorizationStatus(); 672 | switch (authStatus) { 673 | case kABAuthorizationStatusNotDetermined: { 674 | return WQAuthorizationStatusNotDetermined; 675 | break; 676 | } 677 | case kABAuthorizationStatusRestricted: 678 | case kABAuthorizationStatusDenied: { 679 | return WQAuthorizationStatusForbid; 680 | break; 681 | } 682 | case kABAuthorizationStatusAuthorized: { 683 | return WQAuthorizationStatusAuthorized; 684 | break; 685 | } 686 | } 687 | } 688 | } 689 | 690 | - (WQPermissionAuthorizationStatus)determineNetwork { 691 | if ([[[UIDevice currentDevice] systemVersion] floatValue] > 9.0) { 692 | CTCellularData *cellularData = [[CTCellularData alloc] init]; 693 | CTCellularDataRestrictedState authStatus = cellularData.restrictedState; 694 | switch (authStatus) { 695 | case kCTCellularDataRestrictedStateUnknown: { 696 | WQLogMes(@"kCTCellularDataRestrictedStateUnknown"); 697 | return WQAuthorizationStatusNotDetermined; 698 | break; 699 | } 700 | case kCTCellularDataRestricted: { 701 | WQLogMes(@"kCTCellularDataRestricted"); 702 | return WQAuthorizationStatusForbid; 703 | break; 704 | } 705 | case kCTCellularDataNotRestricted: { 706 | WQLogMes(@"kCTCellularDataNotRestricted"); 707 | return WQAuthorizationStatusAuthorized; 708 | break; 709 | } 710 | } 711 | }else { 712 | NSAssert(0, @"* * * * * * iOS 9.0 后才可使用网络授权 * * * * * *"); 713 | return WQAuthorizationStatusForbid; 714 | } 715 | } 716 | 717 | 718 | #pragma mark -- CLLocationManagerDelegate 719 | - (void)locationManager:(CLLocationManager *)manager 720 | didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 721 | WQLogMes(@"didChangeAuthorizationStatus: %d",status); 722 | if (status == kCLAuthorizationStatusAuthorizedAlways 723 | || status == kCLAuthorizationStatusAuthorizedWhenInUse) { 724 | if (self.locationResult) { 725 | self.locationResult(YES, nil); 726 | self.locationResult = nil; 727 | } 728 | } 729 | } 730 | @end 731 | --------------------------------------------------------------------------------