问题
Workspace: iOS 13.0, Xcode 11.0
TL;DR: Is there something wrong with AVAssetReferenceRestrictions in iOS 13?
Part 1:
In AVAsset.h
, the AVAssetReferenceRestrictions
are defined as:
@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
};
And an AVAsset
's property is defined as:
@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);
So, although the documentation on the property explicitly says that the default value is AVAssetReferenceRestrictionForbidNone
, AVAssetReferenceRestrictionDefaultPolicy
is currently AVAssetReferenceRestrictionForbidLocalReferenceToRemote
. Is the documentation not updated properly, or is AVAssetReferenceRestrictionDefaultPolicy
something different than I expect?
Part 2:
In Swift counterpart, it's defined (converted?) as such:
@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 }
}
There is no option as AVAssetReferenceRestrictionForbidNone
here. But the documentation explicitly says that there is so. So, who's in fault here, or is it a misunderstanding from my side?
Part 3: How did I end here?
I've had to examine these because we were able to select a video from
UIImagePickerController
, then export it inAVURLAsset
form to use inAVAssetExportSession
. Everything was fine, it was working seamlessly until iOS 13.0. The feature works in the devices with iOS 12.4.1 and below.The usage of AVAssetReferenceRestrictions is in the initializer of the
AVURLAsset
, and I believe that the default value has changed and it doesn't let us export anymore.
回答1:
It is not your fault.
Until 2019-06-19, in the Apple referenceRestrictions documentation, the default value was forbidNone
:
The default value for this property is forbidNone . See AVURLAssetReferenceRestrictionsKey for a full discussion of reference restrictions.
Later, this page was changed to this:
The default value for this property is defaultPolicy. See AVURLAssetReferenceRestrictionsKey for a full discussion of reference restrictions.
The defaultPolicy now is forbidLocalReferenceToRemote
, available only in iOS 13.
However, we have this paragraph:
For AVURLAsset, this property reflects the value passed in for AVURLAssetReferenceRestrictionsKey, if any.
So, apparently, not passing a restrictionKey should work the same as forbidNone
.
Have you tried this?
let asset = AVURLAsset(url: url, options: nil)
来源:https://stackoverflow.com/questions/58136254/avassetreferencerestrictions-on-ios-13