我使用下面的代碼來檢查MPMediaLibrary授權:檢查MPMediaLibrary授權斯威夫特3
func handlePermissions() {
let permissionStatus = MPMediaLibrary.authorizationStatus()
switch (permissionStatus) {
case MPMediaLibraryAuthorizationStatus.authorized:
print("permission status is authorized")
case MPMediaLibraryAuthorizationStatus.notDetermined:
print("permission status is not determined")
MPMediaLibrary.requestAuthorization(MPMediaLibraryAuthorizationStatus -> permissionStatus)
case MPMediaLibraryAuthorizationStatus.denied:
print("permission status is denied")
case MPMediaLibraryAuthorizationStatus.restricted:
print("permission status is restricted")
}
}
最後,我想提示(一經推出)其授權的用戶調用查詢之前, ...通過案例MPMediaLibraryAuthorizationStatus.notDetermined :.上面的代碼產生錯誤:在' - >'之後的期望類型。當requestAuthorization()行被註釋掉時,應用程序在啓動時崩潰(訪問權限未被授權),並且在啓動屏幕消失後顯示授權提示視圖。
我見過一些如何在Objective C中執行requestAuthorization()但是沒有在Swift中的例子。我不明白:
MPMediaLibrary.requestAuthorization(handler: (MPMediaLibraryAuthorizationStatus) -> Void)
請求授權訪問Swift 3中MPMediaLibrary的正確方法是什麼?