asset/ckasset

来源:互联网 发布:美工抠图 编辑:程序博客网 时间:2024/04/26 08:09

CKAsset object represents a large file associated with a record.(一条记录里包含大文件,使用asset对象进行关联) Use asset objects to incorporate external files—such as image, sound, video, text, and binary data files—into your app’s records. You can also use assets in places where the data you want to assign to a field is more than a few kilobytes in size. To associate an asset with a record, assign it as the value of one of the record’s fields.

The content of an asset is stored separately from the record that references it but is tied closely to that record. When you save a record that has an asset, CloudKit saves both the record and the asset data to the server. Similarly, when you fetch the record, the server returns both the record data and any assets. If multiple records refer to the same asset, however, CloudKit saves or fetches only one copy of the asset data.CloudKit saves only the asset data;it does not save the filename or any other metadataassociated with the initial file you provide.

When you download a record containing an asset, CloudKit keeps the asset data around for a little while but may delete it at any point in the future to free up disk space. After fetching a record containing an asset, you can retrieve the asset data with the URL in the fileURL property. If you want to ensure that the asset’s data remains local to the device, write the data to a file in your app’s local container directory and reference the data from the new file.

You cannot delete asset data directly from the server. When you no longer want the data associated with an asset, remove all asset objects that point to that data from your records. For example, for a record that contains an asset as a field, set the value of the field to nil. When no asset objects refer to the data, the server lazily deletes the asset data at some point in the future. (Exactly when is not specified, but assume at least several days.)

NOTE

The files or data you save using an asset object must be no larger than 250 MB.

0 0