ios向用戶發(fā)起權(quán)限申請

攝像頭權(quán)限
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    switch (status) {
        case AVAuthorizationStatusNotDetermined:{
            // 許可對話沒有出現(xiàn)涕刚,發(fā)起授權(quán)許可
            
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    if (granted) {
                        ScanViewController *scanViewController = [[ScanViewController alloc] initWithType:3];;
                        [self.navigationController pushViewController:scanViewController animated:NO];
                    }else{
                        //用戶拒絕
                        ScanViewController *scanViewController = [[ScanViewController alloc] initWithType:3];
                        [self.navigationController pushViewController:scanViewController animated:NO];
                    }
                });
            }];
        }
            break;
        case AVAuthorizationStatusAuthorized:{
            // 已經(jīng)開啟授權(quán),可繼續(xù)
            ScanViewController *scanViewController = [[ScanViewController alloc] initWithType:3];
            [self.navigationController pushViewController:scanViewController animated:NO];
        }
            break;
        case AVAuthorizationStatusDenied:
        case AVAuthorizationStatusRestricted: {
            // 用戶明確地拒絕授權(quán),或者相機設(shè)備無法訪問
            ScanViewController *scanViewController = [[ScanViewController alloc] initWithType:3];
            [self.navigationController pushViewController:scanViewController animated:NO];
        }
            break;
        default:
            break;
    }

麥克風權(quán)限
 [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                AVAuthorizationStatus statusVideo = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
                AVAuthorizationStatus statusAudio = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
                [ws judgeLianMaiLocationWithVideoPermission:statusVideo AudioPermission:statusAudio];
                [ws.lianMaiView initUIWithVideoPermission:statusVideo AudioPermission:statusAudio];
            });
        }];
iOS 隱私權(quán)限和通過openURL實現(xiàn)跳轉(zhuǎn)實例

<key>NSPhotoLibraryUsageDescription</key> 
<string>訪問相冊</string>
 
<key>NSCameraUsageDescription</key> 
<string>訪問相機</string> 
 
<key>NSContactsUsageDescription</key>
<string>訪問通訊錄</string>
 
<key>NSMicrophoneUsageDescription</key> 
<string>訪問麥克風</string> 
 
<key>NSAppleMusicUsageDescription</key> 
<string>訪問媒體資料庫</string>
 
<key>NSLocationUsageDescription</key> 
<string>訪問位置</string> 
 
<key>NSLocationWhenInUseUsageDescription</key> 
<string>使用期間訪問位置</string> 
 
<key>NSLocationAlwaysUsageDescription</key> 
<string>始終訪問位置</string> 
 
<key>NSCalendarsUsageDescription</key> 
<string>訪問日歷</string> 
 
<key>NSRemindersUsageDescription</key> 
<string>訪問提醒事項</string> 
 
<key>NSMotionUsageDescription</key> 
<string>訪問運動與健身</string> 
 
<key>NSHealthUpdateUsageDescription</key> 
<string>訪問健康更新 </string> 
 
<key>NSHealthShareUsageDescription</key> 
<string>訪問健康分享</string> 
 
<key>NSBluetoothPeripheralUsageDescription</key> 
<string>訪問藍牙</string> 
 
<key>NSSiriUsageDescription</key>
<string>訪問Siri</string>
 
  
<key>NSSpeechRecognitionUsageDescription</key>
<string>訪問語音識別</string>

openUrl

開發(fā)中使用以下代碼可以實現(xiàn)快速撥打電話
NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];

if
(phoneVersion.floatValue < 10.0) {

  
//iOS10 以前使用

  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@
"[Tel://123456](tel://123456)"
]];

}

else
{

  
//iOS10 以后使用

  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@
"[Tel://123456](tel://123456)"
]

                    
options:@{}

               
completionHandler:nil];

}

只要給出對應的URL一膨,系統(tǒng)就可以直接跳:
//撥打電話

[NSURL URLWithString:@
"[tel://123456](tel://123456)"
]

//發(fā)送短信

[NSURL URLWithString:@
"[sms://123456](sms://123456)"
]

//發(fā)郵件

[NSURL URLWithString:@
"[mailto://123456@163.com](mailto://123456@163.com)"
]

//前往App Store

[NSURL URLWithString:@
"itms-[apps://](apps://)"
]

//使用Safari訪問網(wǎng)址

[NSURL URLWithString:@
"[http://www.baidu.com](http://www.baidu.com/)"
]

//前往iBook

[NSURL URLWithString:@
"itms-[books://](books://)"
]

//發(fā)起Facetime

[NSURL URLWithString:@
"[facetime://](facetime://)"
]

//8培己、調(diào)用 地圖Map

[NSURL URLWithString:@
"[maps://](maps://)"
]

//9、調(diào)用 Music

[NSURL URLWithString:@
"[music://](music://)"
]

//10胳嘲、跳轉(zhuǎn)到系統(tǒng)設(shè)置相關(guān)界面

  
// iOS10 以前

  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@
"prefs:root=LOCATION"
] options:@{} completionHandler:nil];

  
// iOS10 以后

  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@
"App-Prefs:root=LOCATION"
] options:@{} completionHandler:nil];

 
#pragma mark - 以下為跳轉(zhuǎn)設(shè)置的對應方式

//設(shè)置

[NSURL URLWithString:UIApplicationOpenSettingsURLString]

 
//iCloud

[NSURL URLWithString:@
"App-Prefs:root=CASTLE"
]

 
//WIFI

[NSURL URLWithString:@
"App-Prefs:root=WIFI"
]

 
//藍牙

[NSURL URLWithString:@
"App-Prefs:root=Bluetooth"
]

 
//蜂窩數(shù)據(jù)

[NSURL URLWithString:@
"App-Prefs:root=MOBILE_DATA_SETTINGS_ID"
]

 
//通知

[NSURL URLWithString:@
"App-Prefs:root=NOTIFICATIONS_ID"
]

 
//通用

[NSURL URLWithString:@
"App-Prefs:root=General"
]

//關(guān)于手機

[NSURL URLWithString:@
"App-Prefs:root=General&path=About"
]

//輔助功能

[NSURL URLWithString:@
"App-Prefs:root=General&path=ACCESSIBILITY"
]

//日期與時間

[NSURL URLWithString:@
"App-Prefs:root=General&path=DATE_AND_TIME"
]

//鍵盤設(shè)置

[NSURL URLWithString:@
"App-Prefs:root=General&path=Keyboard"
]

 
//顯示與亮度

[NSURL URLWithString:@
"App-Prefs:root=DISPLAY"
]

 
//墻紙設(shè)置

[NSURL URLWithString:@
"App-Prefs:root=Wallpaper"
]

 
//聲音

[NSURL URLWithString:@
"App-Prefs:root=Sounds"
]

 
//Siri

[NSURL URLWithString:@
"App-Prefs:root=Siri"
]

 
//隱私

[NSURL URLWithString:@
"App-Prefs:root=Privacy"
]

//定位

[NSURL URLWithString:@
"App-Prefs:root=Privacy&path=LOCATION"
]

 
//電池電量

[NSURL URLWithString:@
"App-Prefs:root=BATTERY_USAGE"
]

 
//iTunes Store 與 App Store

[NSURL URLWithString:@
"App-Prefs:root=STORE"
]

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末温算,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子佳头,更是在濱河造成了極大的恐慌鹰贵,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,681評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件畜晰,死亡現(xiàn)場離奇詭異砾莱,居然都是意外死亡,警方通過查閱死者的電腦和手機凄鼻,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,205評論 3 399
  • 文/潘曉璐 我一進店門腊瑟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人块蚌,你說我怎么就攤上這事闰非。” “怎么了峭范?”我有些...
    開封第一講書人閱讀 169,421評論 0 362
  • 文/不壞的土叔 我叫張陵财松,是天一觀的道長。 經(jīng)常有香客問我,道長辆毡,這世上最難降的妖魔是什么菜秦? 我笑而不...
    開封第一講書人閱讀 60,114評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮舶掖,結(jié)果婚禮上球昨,老公的妹妹穿的比我還像新娘。我一直安慰自己眨攘,他們只是感情好主慰,可當我...
    茶點故事閱讀 69,116評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著鲫售,像睡著了一般共螺。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上情竹,一...
    開封第一講書人閱讀 52,713評論 1 312
  • 那天藐不,我揣著相機與錄音,去河邊找鬼秦效。 笑死佳吞,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的棉安。 我是一名探鬼主播,決...
    沈念sama閱讀 41,170評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼铸抑,長吁一口氣:“原來是場噩夢啊……” “哼贡耽!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起鹊汛,我...
    開封第一講書人閱讀 40,116評論 0 277
  • 序言:老撾萬榮一對情侶失蹤蒲赂,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后刁憋,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體滥嘴,經(jīng)...
    沈念sama閱讀 46,651評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,714評論 3 342
  • 正文 我和宋清朗相戀三年至耻,在試婚紗的時候發(fā)現(xiàn)自己被綠了若皱。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,865評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡尘颓,死狀恐怖走触,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情疤苹,我是刑警寧澤互广,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響惫皱,放射性物質(zhì)發(fā)生泄漏像樊。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,211評論 3 336
  • 文/蒙蒙 一旅敷、第九天 我趴在偏房一處隱蔽的房頂上張望生棍。 院中可真熱鬧,春花似錦扫皱、人聲如沸足绅。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,699評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽氢妈。三九已至,卻和暖如春段多,著一層夾襖步出監(jiān)牢的瞬間首量,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,814評論 1 274
  • 我被黑心中介騙來泰國打工进苍, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留加缘,地道東北人。 一個月前我還...
    沈念sama閱讀 49,299評論 3 379
  • 正文 我出身青樓觉啊,卻偏偏與公主長得像拣宏,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子杠人,可洞房花燭夜當晚...
    茶點故事閱讀 45,870評論 2 361

推薦閱讀更多精彩內(nèi)容