iOS 13 上的 AVAssetReferenceRestrictions
Posted
技术标签:
【中文标题】iOS 13 上的 AVAssetReferenceRestrictions【英文标题】:AVAssetReferenceRestrictions on iOS 13 【发布时间】:2019-09-27 14:11:23 【问题描述】:工作区:ios 13.0、Xcode 11.0
TL;DR:iOS 13 中的 AVAssetReferenceRestrictions 有问题吗?
第 1 部分:
在AVAsset.h
中,AVAssetReferenceRestrictions
定义为:
@enum AVAssetReferenceRestrictions
@abstract These constants can be passed in to AVURLAssetReferenceRestrictionsKey to control the resolution of references to external media data.
@constant AVAssetReferenceRestrictionForbidNone
Indicates that all types of references should be followed.
@constant AVAssetReferenceRestrictionForbidRemoteReferenceToLocal
Indicates that references from a remote asset (e.g. referenced via http URL) to local media data (e.g. stored in a local file) should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToRemote
Indicates that references from a local asset to remote media data should not be followed.
@constant AVAssetReferenceRestrictionForbidCrossSiteReference
Indicates that references from a remote asset to remote media data stored at a different site should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToLocal
Indicates that references from a local asset to local media data stored outside the asset's container file should not be followed.
@constant AVAssetReferenceRestrictionForbidAll
Indicates that only references to media data stored within the asset's container file should be allowed.
*/
typedef NS_OPTIONS(NSUInteger, AVAssetReferenceRestrictions)
AVAssetReferenceRestrictionForbidNone = 0UL,
AVAssetReferenceRestrictionForbidRemoteReferenceToLocal = (1UL << 0),
AVAssetReferenceRestrictionForbidLocalReferenceToRemote = (1UL << 1),
AVAssetReferenceRestrictionForbidCrossSiteReference = (1UL << 2),
AVAssetReferenceRestrictionForbidLocalReferenceToLocal = (1UL << 3),
AVAssetReferenceRestrictionForbidAll = 0xFFFFUL,
AVAssetReferenceRestrictionDefaultPolicy = AVAssetReferenceRestrictionForbidLocalReferenceToRemote
;
而AVAsset
的属性定义为:
@property referenceRestrictions
@abstract Indicates the reference restrictions being used by the receiver.
@discussion
For AVURLAsset, this property reflects the value passed in for AVURLAssetReferenceRestrictionsKey, if any. See AVURLAssetReferenceRestrictionsKey below for a full discussion of reference restrictions. The default value for this property is AVAssetReferenceRestrictionForbidNone.
@property (nonatomic, readonly) AVAssetReferenceRestrictions referenceRestrictions API_AVAILABLE(macos(10.7), ios(5.0), tvos(9.0)) API_UNAVAILABLE(watchos);
因此,尽管该属性的文档明确指出默认值为AVAssetReferenceRestrictionForbidNone
,但AVAssetReferenceRestrictionDefaultPolicy
当前为AVAssetReferenceRestrictionForbidLocalReferenceToRemote
。是文档没有正确更新,还是 AVAssetReferenceRestrictionDefaultPolicy
与我预期的不同?
第 2 部分:
在对应的 Swift 中,它是这样定义(转换的?):
@enum AVAssetReferenceRestrictions
@abstract These constants can be passed in to AVURLAssetReferenceRestrictionsKey to control the resolution of references to external media data.
@constant AVAssetReferenceRestrictionForbidNone
Indicates that all types of references should be followed.
@constant AVAssetReferenceRestrictionForbidRemoteReferenceToLocal
Indicates that references from a remote asset (e.g. referenced via http URL) to local media data (e.g. stored in a local file) should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToRemote
Indicates that references from a local asset to remote media data should not be followed.
@constant AVAssetReferenceRestrictionForbidCrossSiteReference
Indicates that references from a remote asset to remote media data stored at a different site should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToLocal
Indicates that references from a local asset to local media data stored outside the asset's container file should not be followed.
@constant AVAssetReferenceRestrictionForbidAll
Indicates that only references to media data stored within the asset's container file should be allowed.
public struct AVAssetReferenceRestrictions : OptionSet
public init(rawValue: UInt)
public static var forbidRemoteReferenceToLocal: AVAssetReferenceRestrictions get
public static var forbidLocalReferenceToRemote: AVAssetReferenceRestrictions get
public static var forbidCrossSiteReference: AVAssetReferenceRestrictions get
public static var forbidLocalReferenceToLocal: AVAssetReferenceRestrictions get
public static var forbidAll: AVAssetReferenceRestrictions get
public static var defaultPolicy: AVAssetReferenceRestrictions get
这里没有AVAssetReferenceRestrictionForbidNone
的选项。但是文档明确表示确实如此。那么,到底是谁的错,还是我的误解?
第 3 部分:我是如何在这里结束的?
我不得不检查这些 因为我们能够从
UIImagePickerController
中选择一个视频, 然后以AVURLAsset
形式导出它以使用AVAssetExportSession
。 一切都很好,直到 iOS 13.0 都可以无缝运行。该功能适用于 iOS 12.4.1 及更低版本的设备。AVAssetReferenceRestrictions 的用法是在初始化器中
AVURLAsset
,我相信默认值已经改变了 不允许我们再导出。
【问题讨论】:
【参考方案1】:这不是你的错。
直到 2019 年 6 月 19 日,Apple referenceRestrictions documentation 中的默认值为 forbidNone
:
此属性的默认值为 禁止无 .看 AVURLAssetReferenceRestrictionsKey 有关参考限制的完整讨论。
后来这个页面改成了this:
此属性的默认值为 defaultPolicy。有关引用限制的完整讨论,请参阅 AVURLAssetReferenceRestrictionsKey。
defaultPolicy 现在是forbidLocalReferenceToRemote
,仅在 iOS 13 中可用。
但是,我们有这样一段:
对于 AVURLAsset,此属性反映为 AVURLAssetReferenceRestrictionsKey 传入的值,如果有。
因此,显然,不传递限制键应该与 forbidNone
一样工作。
你试过了吗?
let asset = AVURLAsset(url: url, options: nil)
【讨论】:
通过nil
有效,谢谢。我没想到会发生这种重大变化,但是...以上是关于iOS 13 上的 AVAssetReferenceRestrictions的主要内容,如果未能解决你的问题,请参考以下文章
iOS 布局在 Xcode 11 上的 iOS 13 上中断 - 未调用 traitCollectionDidChange
sceneDidEnterBackground 上的 URL 请求(iOS13)
iOS 13 SceneDelegate 上的 WKWebView 警报崩溃