Post

Replies

Boosts

Views

Activity

PHAssetResource.originalFilename can be nil despite non-optional Swift API
In our PhotoKit backup/export code, we need to read PHAssetResource.originalFilename for each resource. The Swift API imports this property as non-optional: var originalFilename: String { get } However, we have customer reports from real Photos libraries where reading this property appears to crash because the underlying Objective-C value is nil at runtime. This affects actual users of our shipping app, not just a synthetic test case. The relevant code path is essentially this: import Photos func inspectAsset(_ asset: PHAsset) { let resources = PHAssetResource.assetResources(for: asset) for resource in resources { // This property is imported as non-optional String. // For some affected customer assets, reading it appears to trap/crash // because the underlying value is nil. let filename: String = resource.originalFilename print(filename) } } This makes the API difficult to use safely from Swift: because the property is non-optional, there is no normal Swift optional-handling path before the crash. We filed this as FB22589474. We also filed a related Feedback, FB22519412, for empty-string / otherwise unusable filename values. That is a separate issue, but it points in the same direction: apps that export, back up, or sync Photos resources cannot treat PHAssetResource.originalFilename as a guaranteed usable filename. For PHAssetResource.originalFilename, what is the intended contract?
3
0
101
1w
PHAssetResource.originalFilename can be nil despite non-optional Swift API
In our PhotoKit backup/export code, we need to read PHAssetResource.originalFilename for each resource. The Swift API imports this property as non-optional: var originalFilename: String { get } However, we have customer reports from real Photos libraries where reading this property appears to crash because the underlying Objective-C value is nil at runtime. This affects actual users of our shipping app, not just a synthetic test case. The relevant code path is essentially this: import Photos func inspectAsset(_ asset: PHAsset) { let resources = PHAssetResource.assetResources(for: asset) for resource in resources { // This property is imported as non-optional String. // For some affected customer assets, reading it appears to trap/crash // because the underlying value is nil. let filename: String = resource.originalFilename print(filename) } } This makes the API difficult to use safely from Swift: because the property is non-optional, there is no normal Swift optional-handling path before the crash. We filed this as FB22589474. We also filed a related Feedback, FB22519412, for empty-string / otherwise unusable filename values. That is a separate issue, but it points in the same direction: apps that export, back up, or sync Photos resources cannot treat PHAssetResource.originalFilename as a guaranteed usable filename. For PHAssetResource.originalFilename, what is the intended contract?
Replies
3
Boosts
0
Views
101
Activity
1w
Identifying Personal vs. Shared Library Assets in Photos.framework
Can Photos.framework distinguish between assets that are stored in the user’s Personal Library and assets that are stored in the Shared Library? If not, is there a planned API that would allow developers to identify the library membership of a PHAsset?
Replies
3
Boosts
0
Views
82
Activity
1w