在这里留下你想说的话。
import
UIKit
import
Alamofire
import
Photos
class
ViewController
:
UIViewController
,
UIImagePickerControllerDelegate
,
UINavigationControllerDelegate
{
override
func
viewDidLoad() {
super
.viewDidLoad()
}
@IBAction
func
fromAlbum(sender:
AnyObject
) {
if
UIImagePickerController
.isSourceTypeAvailable(.
PhotoLibrary
){
let
picker =
UIImagePickerController
()
picker.delegate =
self
picker.sourceType =
UIImagePickerControllerSourceType
.
PhotoLibrary
self
.presentViewController(picker, animated:
true
, completion: {
() ->
Void
in
})
}
else
{
print
(
"读取相册错误"
)
}
}
func
imagePickerController(picker:
UIImagePickerController
,
didFinishPickingMediaWithInfo info: [
String
:
AnyObject
]) {
let
pickedURL:
NSURL
= info[
UIImagePickerControllerReferenceURL
]
as
!
NSURL
let
fetchResult:
PHFetchResult
=
PHAsset
.fetchAssetsWithALAssetURLs([pickedURL],
options:
nil
)
let
asset:
PHAsset
= fetchResult.firstObject
as
!
PHAsset
PHImageManager
.defaultManager()
.requestImageDataForAsset(asset, options:
nil
, resultHandler: {
(imageData:
NSData
?, dataUTI:
String
?, orientation:
UIImageOrientation
,
info: [
NSObject
:
AnyObject
]?)
in
let
imageNSURL:
NSURL
= info![
"PHImageFileURLKey"
]
as
!
NSURL
print
(
"路径:"
,imageNSURL)
print
(
"文件名:"
,imageNSURL.lastPathComponent)
.responseString { response
in
print
(
"Success: \(response.result.isSuccess)"
)
print
(
"Response String: \(response.result.value)"
)
}
})
picker.dismissViewControllerAnimated(
true
, completion:
nil
)
}
override
func
didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
请发表评论