PHAsset Create with Adjustment Data in One Go - ios

TL, DR:
I want to create a new asset in the photo library and apply adjustment data (edits) to it, without the user being prompted twice.
The Background
I am developing an iOS photo editing extension, and providing similar functionality in the container app.
For better code reuse and modularity, I am adopting a PHContentEditingController-based flow on both the extension (required) and the container app, bundling all the shared components in an embedded framework that both the app and the extension link against (as recommended by Apple).
Unlike the app extension, which is "passed" an image to edit by the Photos app and executes under its supervision, the container app needs to request changes to the asset library, each resulting in the user being prompted for authorization.
On launch, the app offers the user two options for sourcing the image to edit:
Opening an existing photo from the library, or
Taking a new photo using the camera.
(both options rely on UIImagePickerController, of course)
Right now, the images read from the library undergo the same editing flow as they would within the app extension, with the only difference that my own UI code manually calls finishContentEditing(completionHandler:) on the (shared) object that adopts the PHContentEditingController protocol, and, on completion, it further calls the PHAssetLibrary method performChanges(_:completionHandler) (which triggers the authorization prompt).
This means that edits made within the container app can be reverted when re-editing the same image with the extension in the Photos app (and potentially vice-versa, too, once I get around supporting adjustment data).
For new images taken with the camera, however, I am taking a different approach. After applying the filters, I just save the result to the photo library using the legacy function:
UIImageWriteToSavedPhotosAlbum(_:_:_:_:)
(back from the time when argument labels weren't a thing yet :-)
The Problem
The problem with this approach is that edits are always 'baked in' for images taken with the camera and edited within the app (the can't be reverted). This feels arbitrary and perhaps even confusing to the user, so I'm looking for a more unified approach.
I could save the photo to the library right after the user takes it, and from there use the same flow as with existing assets, but this means that I need to modiufy the library twice:
Create a new asset
Save edits to the new asset
...which will result in the user being asked for permission twice: Once before editing the image, and once again on committing the edits.
So, my question is:
Is There a Way to Create a Library Asset "In One Go", Original Image and Adjustment Data?

Although I haven't tried this on my code yet (I have more urgent issues now), I seem to have found what seems to be the exact answer to my question in Apple's documentation for one of the initializers of the PHContentEditingOutput class:
init(placeholderForCreatedAsset: PHObjectPlaceholder)
From the docs:
Discussion
Use this method if you want to add a new asset to the Photos library
with edited content, as opposed to editing the content of an asset
after adding it to the library. For example, you might use this option
if your app applies filters to photos it captures with the device
camera—instead of saving only the filtered image to the Photos
library, your app can save both the filtered and the original image,
allowing the user to revert to the original image or apply different
filters later.
Also:
Note
If your app edits the contents of assets already in the Photos
library—including assets your app has itself recently added—Photos
prompts the user for permission to change the asset’s content. If
instead your app uses the init(placeholderForCreatedAsset:) method to
create an asset with edited content, Photos recognizes your app’s
ownership of the content and therefore does not need to prompt the
user for permission to edit it.
I guess we all need a healthy dose of RTFM once in a while! :-)

Related

Original fileURL from ItemProvider and UIDropInteractionDelegate functions

Our iOS application allows users to select an email attachment document and upload it, through our application, to a remote database on a cloud server. We have been doing this successfully using "open in..", which allows us to identify the current fileURL of the document. Using the fileURL, we can both display the document in our application for immediate use, as well as upload it in the background to the remote data base. All good and very fast from a user perspective.
However, on iPad in split-screen mode, we would now also like to allow drag-and-drop, where the user drags the attachment from their email program and drops it on our application. Item Providers are used for this purpose, along with the UIDropInteractionDelegate methods. Unfortunately, these methods seem to want to either copy or move the document, rather than provide us with the existing fileURL. Moving or copying and then uploading the document into our application are both slow and expensive in CPU processing and thus degrade the user experience. We don't want to do anything with the file on the device. All we want is to get the existing fileURL. We will take it from there!
Question: How can we find the existing fileURL of a "dropped" document, using the Item Provider and the UIDropInteractionDelegate methods?

How do I update my iOS app's content with background downloading?

TL;DR: I want to add images to the app over the internet through background downloading of some sort, but don't know where to start, or what the best method is.
My app displays images to the users which can be filtered etc. I have a "Cards" class that has fields for name, image, etc. I then have a huge area directly in my code where I create instances of the Cards class for each image. There is then an array of these class instances, which helps with displaying them.
My issue is that now I want to be able to update this block of class instances without having to push another build to the iTunes store. Essentially, I want to add "Cards" to the app (images with appropriate names and keywords associated with them). I need to be able to update the app every month (sometimes less) with new cards as quickly as possible.
I have heard suggestions here and there about JSON files and background downloading, but can't figure out which method I need for my situation.
As per my understanding you just want to update your app content in future without uploading a new build to App Store. Right ?
If you want to do so, make your app so flexible that you can show updated contents in your app.
Here is a short instruction which you can follow...
Develop an admin panel if you are aware of any backend scripting language like php. And you can add contents from this panel into your database.
Create an API which will fetch the content from your database
Make your app flexible so that it can show all the updated content getting from the API. If you have a list of content then you can use TableView/CollectionView with pagination.
If you still face any problem then let me know. I will see deep into your problem.

iOS app that creates HTML5 content

I'm trying to do something a bit complicated and I'm not entirely sure how to go about it. Could you please give me some pointers on the tech I should use and how I should go about implementing this. Here's what I need to do:
Create an iOS app that allows the user to upload pictures from his camera roll and modify variables with sliders. (so far so good)
These variables and graphics are used to modify some htlm5 code (i.e. the graphics the user supplies are called by the hmtl code and the variables modify some set variables in the script) (Do I just edit the code as a string?)
The code is put together and uploaded to a server where it is accessible at a unique URL. The user can save multiple times and each time it creates a new URL. (Do I need an FTP here?)
Your question is too general, but as far as I can help, Yes you have to create and edit some html source texts, and append every object that user is adding to the page as some html codes, files, css, etc.
and for uploading, if you want the user to upload the site to his/her own ftp server or web hosting service, yes you need FTP connection to create with the server.
But if you want your user to upload the website to a space you're providing for the user, then you need some server part and maybe some APIs. then you may use FTP or even some APIs to create and update files on your server. It highly depends on the service you want to provide.

Concurrent photo and note uploading

I have this requirement whereby the user is uploading a photo from the phone, and typing a note along with the photo
However, to vastly improve responsiveness, I would like to start uploading the photo before the user has finished typing the note (the same technique instagram uses)
So, there are 3 scenarios:
- the photo uploading finishes, then the note is submitted
- the note is submitted, then the photo finishes uploading
- the note and photo finishes uploading at the same time
I am using a unique token, as well as after_create hooks now to check and save.
a unique uuid comes along with both the photo upload and the note
store the photo in a temporary store with the uniqueid
when the photo is saved (after_create), check if there are any notes with the uniqueid. If so, attach the photo to note.
store the note with the uniqueid
when the note is saved (after_create), check if there are any photos with the uniqueid. If so, attach note to photo
This seems like a rather common problem, and I am wondering whether there are any accepted patterns / solutions around this? I am using mongoid and rails 3.2
To avoid concurrency problems, and UI confusions. What I would do, in your case, is:
User choses the photo -> set local variable in JS(client) -> servers starts uploading the photo
( when server respond back from the photo upload, unset the local js var )
User write notes
User submits the form -> you check if the js variable is set or not, if it is, means that photo was not uploaded yet, so you show a message. Otherwise you just submit the form with the note.
If you simplify your flow to be something like that, you should not have too much edgecases to have to debug and fix.
The only potential risk in here, is a 'deadlock' case, lets say for some reason server never send back a response to client, which never unset the js var. To avoid those cases you could have a big timeout on the client, that if there server dont respond within that timeout you show an error message.

iOS Creating a User Manual for an App

I need to add a User Manual for my App, although all the user manual examples I have seen are web-based, which is convienent because it allows you to update the documentation without updating the app but also inconvient if the user is in a off-line mode.
What I envision in a helpful usermanual would be a popovercontroller that would display relevant data to whatever the current view has. It would retrieve documentation from the web and save it for later reference. Maybe even something that could take a document and break it into a plist by tag. Including gaphics would be nice also.
Are there any frameworks do to this available? ..... Or am I going to have to write my own.
How have other people implemented user manuals?

Resources