I get the Asset Library URL for a photo using the UIImagePickerControllerReferenceURL key on the info dictionary obtained from UIImagePickerController. The url looks like this:
assets-library://asset/asset.JPG?id=1000000002&ext=JPG
Is this URL stable? Can I expect to save it in a document and then at a later date fetch the photo using this URL?
I basically have a iOS photo editing app where I allow the user to do some editing on a bunch of photos. I allow the user to save the project and edit at a later date. I would save these URLs to save the information about which photos are used in the project. I don't want to copy and save all the photos used in a project since there can be many photos used in a project and this will result in unnecessary duplication.
Can you also suggest if there is a better way around.
Asset URLs are supposed to be stable but the format changed between iOS3 and iOS4 and the format in iOS5 is something like '/asset/FA8F1400-82A5-424F-A98C-2883754FA54D.jpg'. You shouldn't store asset URLs and expect them to remain valid forever, which is a shame because that is exactly what you would expect.
You could protect yourself by storing the asset's date and maybe location if it is set. Then if your app needs to, it can go through the asset library and patch up the references if the URL format changes again.
Related
I know that UIImagePickerController allows you to compress media content upon selection. However, I'm not sure how to do the same with PHPickerViewController. How can I compress a video after getting a result (didFinishPicking), (so I can reduce the amount of time to upload and download the data from then on)
I don't think PHPickerViewController does that, but there are other ways to do it depending on how you work with the picker:
If you're using the default picker configuration (i.e. creating a PHPickerConfiguration without passing the photo library and therefore not having the need to request permissions), you'll have to work with NSItemProvider. From what I learned, the only option might be to save the video to a temporary file using the item provider and the convert it to a lower resolution/bitrate using AVAssetExportSession (see some examples here: How can I reduce the file size of a video created with UIImagePickerController?).
If you are using the picker with an explicitly passed photo library, the PHPickerResult will have the assetIdentifier provided to you, and you can use it to get a respective PHAsset. Then, use PHImageManager's requestAVAsset method to get a video asset of a desired quality. You'll still need to export the AVAsset via AVAssetExportSession though, but with this approach you won't have a (potentially large) full-res temporary file on disk. I was recently working on a open source app that uses this technique, you can find some examples here: https://github.com/vadimbelyaev/TbilisiCleanups/blob/main/TbilisiCleanups/Services/MediaUploadService.swift
I need to record video and upload them to Server. They will be added in queue and uploaded one by one.
My question is, when i record a video, where should i save it till it gets uploaded ?
Should i save it in Album ? or in private documents directory ?
I also need to delete the video once it is uploaded.
According to ios guidelines, is it required to save the video in Albums only ? Will my app be rejected if it is saved in Documents directory for longer period?
If they are not user-created (or if you do not want them to participate in stuff like iCloud), then do not put them in APPHOME/Documents.
The preferred location is APPHOME/Library/Caches but that location can get cleaned by the iOS on a system restore (and possibly other times -- documentation does not specify). It's not going to happen on a regular basis though, so it's the first option if you can regenerate the data on rare occasions like restore.
So, if the files can be recreated, keep them in APPHOME/Library/Caches. If they cannot, then place them somewhere else in APPHOME/Library.
Just make sure you remove them when you are done with the upload.
You're ok, you can save/delete them in/from the Documents directory. Instead, you can't delete videos/photos from the user's albums. No problem for the "longer period".
I'm doing a little iOS app for the subway of my city. It has the following features
See the map (takes you to a UIImageView to see the map of the stations)
See status (tells you if there are problems with one of the lines/stations)
See prices (tells you the different tariffs, depending on the hour)
Subway-news (little feed with the title and the first paragraph of each article, with a link to see more in safari)
Our promotions to you (takes you to a view with image-coupons shown in a overflow fashion. If you click them, you go to a certain page)
I have a server that takes the news and encode them in JSON. From the iPhone, I request the JSON async, parse it and store the info in an NSArray of NSDictionaries (with keys: date, title, content, seeMoreUrl)
This could be bought as a little RSS feed. I saw some examples and they used a SQLite db to store the data. I'm not sure how necessary would this be, as I'm only planning on showing the 5 latest news and I'm not loading the whole content, just title and a iPhone-designed paragraph.
I have serious doubts with the promotions tough. I would request a file called promotions.json with the url of each promotion and the url they link to, like this
[
{
"imgSource":"http:\/\/www.domain.com\/promotions\/1.png",
"url":"http:\/\/www.domain.com\/freeRide"
},
{
"imgSource":"http:\/\/www.domain.com\/promotions\/54.png",
"url":"http:\/\/www.cheapCarRental.com\/promotions-to-subway-users"
}
]
Then, I don't know what to do. Should I download all images to the documents folder and then when the users click in view promotions, load every pic I found in that directory intro the coverflow-like View?
Should I implement a SQLite for the news and also use it to store the images as BLOBs?
Should I just keep them in memory?
You could save the images to the Library/Caches folder (Apple won't like saving to Documents folder without good reason - my app was rejected because of this. See guidelines.). Then, you have a cache file, which is essentially a plist that saves the url (the key) and the path of its corresponding image saved on the disk (the value).
What do you want your app to do? What will users want the app to do? Would they prefer to pay the price in terms of data usage and battery usage to download all the images and probably get a snappier user experience, or would they prefer occasional lags in the interface as images are downloaded on demand in return for longer battery life and decreased data usage? It's up to you to balance those factors.
I'm working on UIDocument application and I'd like to show the user a preview of the document before he opens it. I can render that preview into an image when the document get's closed. But where should I save that image? In an other file? or is there a designated way to do this?
Right now I'm developing it without iCloud support. But I want to have a solution that would work with iCloud too. The UIDocument is a UIManagedDocument. But saving the image into the database would make it kind a pointless. Because then I have to open the document before I can get the preview.
What do you recommend here? Where to put a preview for a UIManagedDocument?
You can store your documents in your ubiquity container's Documents directory and document preview files in the container's Data directory.
If preview file names will be based on the documents names you will be able to use metadata query result to get the document names and then resolve document preview urls.
This way you could download the document previews only but not the whole document.
I don't know about UIManagedDocuments, but in case of a UIDocument I would recommend using a NSFileWrapper as file format (where the document is actually a bundled folder) and save the preview within the document, as "Preview.jpg" (or .png) inside a folder labeled "QuickLook".
This way, you'll get the preview in Finder on the Mac as well (for free).
Of course this may or may not be an ideal solution (also depending on if your document is text-only). But it might be a good hint for working with previews for UIDocuments in general.
You should save an image under (app_directory)/Library/Caches. That way iCloud won't affect your app.
As per my query from the below link, i've implemented retrieving photo album images from ALAsset Library.
Upload ALAsset URL images to the server
I get the images Asset URL's like below,
"assets-library://asset/asset.JPG?id=1000000001&ext=JPG"
"assets-library://asset/asset.JPG?id=1000000002&ext=JPG"
"assets-library://asset/asset.JPG?id=1000000003&ext=JPG"
I want to store these in a database (or) file [I don't know which is suitable for comparison for later purposes]. Next time(say,after 30 mins), i want to get again all the image URL's from Asset and compare with the previous image URL's which has stored in a DB, to find if any new images has been added in photo album or not. If any new image is been added in photo album, then i get that image in my code.
I want to know, what should i use to store the image URL strings, whether SQLite database (or) file, and next time which one should be sufficient to compare the previous data and the current data? I thought of going with creating sqlite database and store the data and compare the image URL strings with the stored data like that …. Am i thinking right to go? If yes, may i know how to store the data(image URL strings) in a sqlite database and do comparison between new image URL's and stored data?
I created a sqlite database through Firefox sqlite manager plugin and added a table. I'm not getting any samples further to go through to solve my purposes, i.e. store the image URL strings in sqlite database and do comparison between the stored image URL strings and new image URL strings which i got from Asset library.
Please help and advise.
Thank you!
yes you are going right. Use sqlite database to store URLs follow the tutorial
http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/
Edit..sorry, i missed the last comment that explains what you want to do..
Here
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html
do that tutorial to learn how to set up the database and core data, you'll see how they save information - and from there just change code to suit your needs
Edit again.. after that you can use predicates to pull out info you need, and/or use string comparisons (Google "iPhone sdk compare strings") to compare to a new string.
or create an array of existing URL's and do something like
if ([myArrayOfURLS containsObject:theNewUrl]) {
[self doSomethingWithMyNewURLIGuess];
}