ユーザーに許可を得る

Preview photokit001

Swift 3.0

Info.plistNSPhotoLibraryUsageDescriptionを追加します

//
//  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のイニシャルが小文字に変更

Reference

results matching ""

    No results matching ""