由于某种原因location
财产在PHAsset
仅在 Objective-c 中公开,在 Swift 中不公开。
文档:PHAsset.location https://developer.apple.com/library/prerelease/ios/documentation/Photos/Reference/PHAsset_Class/index.html#//apple_ref/occ/instp/PHAsset/location
为了解决这个问题,我想我可以创建一个 Objective-C 类,其唯一目的是提取位置并将其导入到 Swift 中。
LocationGetter.h
@interface LocationGetter : NSObject
+ (CLLocation *)locationForAsset:(PHAsset *) asset;
@end
LocationGetter.m
@implementation LocationGetter
+ (CLLocation *)locationForAsset:(PHAsset *) asset {
return [asset location];
}
@end
到目前为止一切顺利,但是当我尝试在 Swift 中使用它时:
LocationGetter.locationForAsset(ass)
“LocationGetter.Type”没有名为“locationForAsset”的成员
额外问题:苹果到底为什么不曝光location
快点?
事实证明,答案其实很简单。问题是 Swift 文件不知道什么是CLLocation
是,因此拒绝导入该函数。输入CoreLocation
解决了这个问题。
import CoreLocation
LocationGetter.locationForAsset(ass)
EDIT:苹果公司此后已将.location
作为吸气剂PHAsset
。获取位置现在非常简单asset.location
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)