Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
b24662a9
Commit
b24662a9
authored
Aug 02, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-479: Additional functionality added to PhotoLibrary class to load PHAssets
parent
912d880b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
71 deletions
+117
-71
Sources/iOS/PhotoLibrary.swift
+117
-71
No files found.
Sources/iOS/PhotoLibrary.swift
View file @
b24662a9
...
...
@@ -225,43 +225,6 @@ public class PhotoLibrary: NSObject {
}
/**
A method to request authorization from the user to enable photo library access. In order
for this to work, set the "Privacy - Photo Library Usage Description" value in the
application's info.plist.
- Parameter _ completion: A completion block that passes in a PHAuthorizationStatus
enum that describes the response for the authorization request.
*/
public
func
requestAuthorization
(
_
completion
:
((
PHAuthorizationStatus
)
->
Void
)?
=
nil
)
{
PHPhotoLibrary
.
requestAuthorization
{
[
weak
self
,
completion
=
completion
]
(
status
)
in
guard
let
s
=
self
else
{
return
}
switch
status
{
case
.
authorized
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
authorized
)
s
.
delegate
?
.
photoLibrary
?(
authorized
:
s
)
completion
?(
.
authorized
)
case
.
denied
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
denied
)
s
.
delegate
?
.
photoLibrary
?(
denied
:
s
)
completion
?(
.
denied
)
case
.
notDetermined
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
notDetermined
)
s
.
delegate
?
.
photoLibrary
?(
notDetermined
:
s
)
completion
?(
.
notDetermined
)
case
.
restricted
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
restricted
)
s
.
delegate
?
.
photoLibrary
?(
restricted
:
s
)
completion
?(
.
restricted
)
}
}
}
/**
Fetch all the PHAssetCollections asynchronously based on a type and subtype.
- Parameter type: A PHAssetCollectionType.
- Parameter subtype: A PHAssetCollectionSubtype.
...
...
@@ -315,36 +278,6 @@ public class PhotoLibrary: NSObject {
}
/**
Fetch the PHAssets in a given PHAssetCollection.
- Parameter in assetCollection: A PHAssetCollection.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
in
assetCollection
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
fetchResult
:
PHFetchResult
<
PHAsset
>!
var
assets
=
[
PHAsset
]()
defer
{
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
assets
,
fetchResult
!
)
}
}
fetchResult
=
PHAsset
.
fetchAssets
(
in
:
assetCollection
,
options
:
options
)
fetchResult
.
enumerateObjects
(
options
:
[])
{
(
asset
,
_
,
_
)
in
assets
.
append
(
asset
)
}
}
/**
*/
public
func
fetchAssets
(
with
mediaType
:
PHAssetMediaType
,
options
:
PHFetchOptions
?)
->
PHFetchResult
<
PHAsset
>
{
return
PHAsset
.
fetchAssets
(
with
:
mediaType
,
options
:
options
)
}
/**
Performes an asynchronous change to the PHPhotoLibrary database.
- Parameter _ block: A transactional block that ensures that
all changes to the PHPhotoLibrary are atomic.
...
...
@@ -372,6 +305,46 @@ public class PhotoLibrary: NSObject {
}
}
/// Authorization.
extension
PhotoLibrary
{
/**
A method to request authorization from the user to enable photo library access. In order
for this to work, set the "Privacy - Photo Library Usage Description" value in the
application's info.plist.
- Parameter _ completion: A completion block that passes in a PHAuthorizationStatus
enum that describes the response for the authorization request.
*/
public
func
requestAuthorization
(
_
completion
:
((
PHAuthorizationStatus
)
->
Void
)?
=
nil
)
{
PHPhotoLibrary
.
requestAuthorization
{
[
weak
self
,
completion
=
completion
]
(
status
)
in
guard
let
s
=
self
else
{
return
}
switch
status
{
case
.
authorized
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
authorized
)
s
.
delegate
?
.
photoLibrary
?(
authorized
:
s
)
completion
?(
.
authorized
)
case
.
denied
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
denied
)
s
.
delegate
?
.
photoLibrary
?(
denied
:
s
)
completion
?(
.
denied
)
case
.
notDetermined
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
notDetermined
)
s
.
delegate
?
.
photoLibrary
?(
notDetermined
:
s
)
completion
?(
.
notDetermined
)
case
.
restricted
:
s
.
delegate
?
.
photoLibrary
?(
photoLibrary
:
s
,
status
:
.
restricted
)
s
.
delegate
?
.
photoLibrary
?(
restricted
:
s
)
completion
?(
.
restricted
)
}
}
}
}
/// PHImageManager.
extension
PhotoLibrary
{
/**
...
...
@@ -408,7 +381,19 @@ extension PhotoLibrary {
}
/**
Requests a live photo representation of the asset. With
oportunistic (or if no
options are specified), the resultHandler block may be
called more than once (the first call may occur before
the method returns). The PHImageResultIsDegradedKey key
in the result handler's info parameter indicates when a
temporary low-quality live photo is provided.
- Parameter for asset: A PHAsset.
- Parameter targetSize: A CGSize.
- Parameter contentMode: A PHImageContentMode.
- Parameter options: A PHImageRequestOptions.
- Parameter completion: A completion block.
- Returns: A PHImageRequestID.
*/
@available(iOS 9.1, *)
public
func
requestLivePhoto
(
for
asset
:
PHAsset
,
targetSize
:
CGSize
,
contentMode
:
PHImageContentMode
,
options
:
PHLivePhotoRequestOptions
?,
completion
:
(
PHLivePhoto
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
...
...
@@ -416,21 +401,33 @@ extension PhotoLibrary {
}
/**
For playback only.
- Parameter forVideo asset: A PHAsset.
- Parameter options: A PHImageRequestOptions.
- Parameter completion: A completion block.
- Returns: A PHImageRequestID.
*/
public
func
requestPlayerItem
(
forVideo
asset
:
PHAsset
,
options
:
PHVideoRequestOptions
?,
completion
:
(
AVPlayerItem
?,
[
NSObject
:
AnyObject
]?)
->
Swift
.
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestPlayerItem
(
forVideo
:
asset
,
options
:
options
,
resultHandler
:
completion
)
}
/**
Export.
- Parameter forVideo asset: A PHAsset.
- Parameter options: A PHImageRequestOptions.
- Parameter completion: A completion block.
- Returns: A PHImageRequestID.
*/
public
func
requestExportSession
(
forVideo
asset
:
PHAsset
,
options
:
PHVideoRequestOptions
?,
exportPreset
:
String
,
completion
:
(
AVAssetExportSession
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestExportSession
(
forVideo
:
asset
,
options
:
options
,
exportPreset
:
exportPreset
,
resultHandler
:
completion
)
}
/**
For all other requests.
- Parameter forVideo asset: A PHAsset.
- Parameter options: A PHImageRequestOptions.
- Parameter completion: A completion block.
- Returns: A PHImageRequestID.
*/
public
func
requestAVAsset
(
forVideo
asset
:
PHAsset
,
options
:
PHVideoRequestOptions
?,
completion
:
(
AVAsset
?,
AVAudioMix
?,
[
NSObject
:
AnyObject
]?)
->
Void
)
->
PHImageRequestID
{
return
PHImageManager
.
default
()
.
requestAVAsset
(
forVideo
:
asset
,
options
:
options
,
resultHandler
:
completion
)
...
...
@@ -487,6 +484,55 @@ extension PhotoLibrary {
}
}
/// PHAsset.
extension
PhotoLibrary
{
/**
Fetch the PHAssets in a given PHAssetCollection.
- Parameter in assetCollection: A PHAssetCollection.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
in
assetCollection
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
fetchResult
:
PHFetchResult
<
PHAsset
>!
var
assets
=
[
PHAsset
]()
defer
{
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
assets
,
fetchResult
!
)
}
}
fetchResult
=
PHAsset
.
fetchAssets
(
in
:
assetCollection
,
options
:
options
)
fetchResult
.
enumerateObjects
(
options
:
[])
{
(
asset
,
_
,
_
)
in
assets
.
append
(
asset
)
}
}
/**
Fetch the PHAssets with a given media type.
- Parameter in mediaType: A PHAssetMediaType.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
with
mediaType
:
PHAssetMediaType
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
fetchResult
:
PHFetchResult
<
PHAsset
>!
var
assets
=
[
PHAsset
]()
defer
{
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
assets
,
fetchResult
!
)
}
}
fetchResult
=
PHAsset
.
fetchAssets
(
with
:
mediaType
,
options
:
options
)
fetchResult
.
enumerateObjects
(
options
:
[])
{
(
asset
,
_
,
_
)
in
assets
.
append
(
asset
)
}
}
}
/// PHPhotoLibraryChangeObserver extension.
extension
PhotoLibrary
:
PHPhotoLibraryChangeObserver
{
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment