ユーザーに許可を得る
Swift 3.0
Info.plist
にNSPhotoLibraryUsageDescription
を追加します
//
// ViewController.swift
// phptokit001
//
// Copyright © 2016年 FaBo, Inc. All rights reserved.
//
import UIKit
import Photos
class ViewController: UIViewController {
override func viewDidLoad() {
// ユーザーに許可を促す.
PHPhotoLibrary.requestAuthorization({ status in
switch status {
case .authorized:
print("Authorized")
case .denied:
print("Denied")
case .notDetermined:
print("NotDetermined")
case .restricted:
print("Restricted")
}
})
}
}
Swift 2.3
//
// ViewController.swift
// phptokit001
//
// Copyright © 2016年 FaBo, Inc. All rights reserved.
//
import UIKit
import Photos
class ViewController: UIViewController {
override func viewDidLoad() {
// ユーザーに許可を促す.
PHPhotoLibrary.requestAuthorization({ status in
switch status {
case .Authorized:
print("Authorized")
case .Denied:
print("Denied")
case .NotDetermined:
print("NotDetermined")
case .Restricted:
print("Restricted")
}
})
}
}
2.xと3.xの差分
- enum列挙体
PHAuthorizationStatus
のイニシャルが小文字に変更