标签:lsp animate 自动跳转 containe 麦克风 授权 eterm 相册 跳转
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import UIKit import Photos class ViewController : UIViewController { override func viewDidLoad() { _ = authorize() } func authorize()-> Bool { let status = PHPhotoLibrary .authorizationStatus() switch status { case .authorized: return true case .notDetermined: // 请求授权 PHPhotoLibrary .requestAuthorization({ (status) -> Void in DispatchQueue .main.async(execute: { () -> Void in _ = self .authorize() }) }) default : () DispatchQueue .main.async(execute: { () -> Void in let alertController = UIAlertController (title: "照片访问受限" , message: "点击“设置”,允许访问您的照片" , preferredStyle: .alert) let cancelAction = UIAlertAction (title: "取消" , style: .cancel, handler: nil ) let settingsAction = UIAlertAction (title: "设置" , style: . default , handler: { (action) -> Void in let url = URL (string: UIApplicationOpenSettingsURLString ) if let url = url, UIApplication .shared.canOpenURL(url) { if #available(iOS 10, *) { UIApplication .shared.open(url, options: [:], completionHandler: { (success) in }) } else { UIApplication .shared.openURL(url) } } }) alertController.addAction(cancelAction) alertController.addAction(settingsAction) self .present(alertController, animated: true , completion: nil ) }) } return false } override func didReceiveMemoryWarning() { super .didReceiveMemoryWarning() } } |
Swift - 判断是否有某功能访问权限,没有则提示,并自动跳转到设置页
标签:lsp animate 自动跳转 containe 麦克风 授权 eterm 相册 跳转
原文地址:http://www.cnblogs.com/Free-Thinker/p/7118024.html