Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dz_TZImagePickerController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shuijing
dz_TZImagePickerController
Commits
ec731436
Commit
ec731436
authored
Jun 30, 2016
by
Zhen Tan
Committed by
GitHub
Jun 30, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #107 from Arthurli/index-beyond-crash
处理根据索引获取数据引起的崩溃问题
parents
50f3e701
6fe247c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
20 deletions
+38
-20
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+38
-20
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
ec731436
...
...
@@ -224,10 +224,18 @@ static CGFloat TZScreenScale;
}
/// Get asset at index 获得下标为index的单个照片
/// if index beyond bounds, return nil in callback 果索引越界, 在回调中返回 nil
-
(
void
)
getAssetFromFetchResult
:(
id
)
result
atIndex
:(
NSInteger
)
index
allowPickingVideo
:(
BOOL
)
allowPickingVideo
allowPickingImage
:(
BOOL
)
allowPickingImage
completion
:(
void
(
^
)(
TZAssetModel
*
))
completion
{
if
([
result
isKindOfClass
:[
PHFetchResult
class
]])
{
PHFetchResult
*
fetchResult
=
(
PHFetchResult
*
)
result
;
PHAsset
*
asset
=
fetchResult
[
index
];
PHAsset
*
asset
;
@try
{
asset
=
fetchResult
[
index
];
}
@catch
(
NSException
*
e
)
{
if
(
completion
)
completion
(
nil
);
return
;
}
TZAssetModelMediaType
type
=
TZAssetModelMediaTypePhoto
;
if
(
asset
.
mediaType
==
PHAssetMediaTypeVideo
)
type
=
TZAssetModelMediaTypeVideo
;
...
...
@@ -251,26 +259,36 @@ static CGFloat TZScreenScale;
[
group
setAssetsFilter
:[
ALAssetsFilter
allPhotos
]];
}
NSIndexSet
*
indexSet
=
[
NSIndexSet
indexSetWithIndex
:
index
];
[
group
enumerateAssetsAtIndexes
:
indexSet
options
:
NSEnumerationConcurrent
usingBlock
:^
(
ALAsset
*
result
,
NSUInteger
index
,
BOOL
*
stop
)
{
TZAssetModel
*
model
;
TZAssetModelMediaType
type
=
TZAssetModelMediaTypePhoto
;
if
(
!
allowPickingVideo
){
model
=
[
TZAssetModel
modelWithAsset
:
result
type
:
type
];
@try
{
[
group
enumerateAssetsAtIndexes
:
indexSet
options
:
NSEnumerationConcurrent
usingBlock
:^
(
ALAsset
*
result
,
NSUInteger
index
,
BOOL
*
stop
)
{
if
(
!
result
)
return
;
TZAssetModel
*
model
;
TZAssetModelMediaType
type
=
TZAssetModelMediaTypePhoto
;
if
(
!
allowPickingVideo
){
model
=
[
TZAssetModel
modelWithAsset
:
result
type
:
type
];
if
(
completion
)
completion
(
model
);
return
;
}
/// Allow picking video
if
([[
result
valueForProperty
:
ALAssetPropertyType
]
isEqualToString
:
ALAssetTypeVideo
])
{
type
=
TZAssetModelMediaTypeVideo
;
NSTimeInterval
duration
=
[[
result
valueForProperty
:
ALAssetPropertyDuration
]
integerValue
];
NSString
*
timeLength
=
[
NSString
stringWithFormat
:
@"%0.0f"
,
duration
];
timeLength
=
[
self
getNewTimeFromDurationSecond
:
timeLength
.
integerValue
];
model
=
[
TZAssetModel
modelWithAsset
:
result
type
:
type
timeLength
:
timeLength
];
}
else
{
model
=
[
TZAssetModel
modelWithAsset
:
result
type
:
type
];
}
if
(
completion
)
completion
(
model
);
return
;
}
/// Allow picking video
if
([[
result
valueForProperty
:
ALAssetPropertyType
]
isEqualToString
:
ALAssetTypeVideo
])
{
type
=
TZAssetModelMediaTypeVideo
;
NSTimeInterval
duration
=
[[
result
valueForProperty
:
ALAssetPropertyDuration
]
integerValue
];
NSString
*
timeLength
=
[
NSString
stringWithFormat
:
@"%0.0f"
,
duration
];
timeLength
=
[
self
getNewTimeFromDurationSecond
:
timeLength
.
integerValue
];
model
=
[
TZAssetModel
modelWithAsset
:
result
type
:
type
timeLength
:
timeLength
];
}
else
{
model
=
[
TZAssetModel
modelWithAsset
:
result
type
:
type
];
}
if
(
completion
)
completion
(
model
);
}];
}];
}
@catch
(
NSException
*
e
)
{
if
(
completion
)
completion
(
nil
);
}
}
}
...
...
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