where to store downloadable in-app purchases?

2019-03-31 14:33发布

my app has downloadable in-app purchases. When the content is downloaded I am storing it right now on the documents directory. But I know Apple is nitpick and will probably reject my app because content that could be restored should not be stored on the documents directory, that means, will be saved to icloud.

I thought of using temp or cache directories but these can be emptied any time when iOS needs space.

Where should I save it?

3条回答
The star\"
2楼-- · 2019-03-31 14:51

I also read the document folder is for user generated content and have been advised to use the cache folder despite of the fact that your data can be deleted when needed. I also read that using the document folder with the no backup flag can be a choice when targeting ios 5.1 and up.

See iOS 5.0.1 : How to verify that the folder is marked as "Do not back up" for iCloud?

Adding the "Do Not Backup" attribute to a folder hierarchy in iOS 5.0.1

查看更多
叛逆
3楼-- · 2019-03-31 14:58

The Documents directory can only be used for user generated data that cannot be downloaded (including potential databases that contain user selectable settings and similar), so you're right, you will probably be rejected if you store downloadable content there.

The way I've done it is to store the downloaded data in Cache (which as you say can be cleared at any time when space is low), and store a small piece of data in Documents that says that the content should be in Cache. When Documents says that the data should be there and it's not, I'll notify the user that the content has been automatically removed by iOS due to space issues, and offer the user to download it again.

That way, if the user does not use the content for a while, he can reuse the space on his device for other things, and can still download the content again at will. Just like I'd want an app to work if I were the user :)

EDIT: You can put them in Library if you need them to be always persistent, but remember to mark them as not backed up to iCloud or you'll most likely get the same rejection.

查看更多
淡お忘
4楼-- · 2019-03-31 15:10

The documentation here https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/DeliverProduct.html#//apple_ref/doc/uid/TP40008267-CH5-SW5

says the Documents folder is the place to move the content if you want it to persist.

In iOS, your app can manage the downloaded files. The files are saved for you by the Store Kit framework in the Caches directory with the backup flag unset. After the download completes, your app is responsible for moving it to the appropriate location. For content that can be deleted if the device runs out of disk space (and later re-downloaded by your app), leave the files in the Caches directory. Otherwise, move the files to the Documents folder and set the flag to exclude them from user backups.

查看更多
登录 后发表回答