Save photo to camera roll with specific filename - ios

What I try to achieve is to take a photo and let the user specify if the photo belongs to category 1 or category 2. I have 2 buttons, one for each category. When the user presses the button, the photo is saved to the camera roll. AFterwards, at home, when I sync my iPad with iPhoto, I want to be able to sort by category, or at least identify to with category it belongs...
I first thought of the following :
1) taking a photo using the iPad camera -- this is already done in my app
2) saving the photo in camera roll under a specific name, such as cat1_pict123.jpg or cat2_pict456.jpg
I would plan to use
UIImageWriteToSavedPhotosAlbum(myImage, nil, nil, nil );
but I don't know how / or if it is possible to specify a file name ?
Alternatively, is there a way to "tag" a photo before saving it to camera roll ? A comment or something else, which will be visible in iPhoto ?
Thank you for your help

You can't use file names for images saved in photolibrary.
Save that to Document directory with specific name.

There is a way to kinda do that, by setting the image IPTC metadata:
Set the field "Object Name" to set the image title in
iPhoto.
Set the field "Keywords" to set the keywords in
iPhoto, then use a smart album to see all the images with these
keywords.
See details (and code) at http://ootips.org/yonat/how-to-set-the-image-name-when-saving-to-the-camera-roll/ .

That's not possible right now.

Related

How to insert a newly created PHAsset at a specific position in camera roll?

Is it possible to insert a new PHAsset to an appointed index in the camera roll?
I tried following:
let cam_req = PHAssetCollectionChangeRequest(for: camera_roll)
cam_req?.insertAssets([asset] as NSArray, at: IndexSet(integer: pos))
doesn't work.
The Camera Roll is like a stack. It's sorted by import date. There is no way to change the order or to insert a photo/video at a specific position. If you want to do that you have to create a custom user album. Custom user albums contain references to the originals in the Camera Roll and can be reordered.
http://www.tapsmart.com/tips-and-tricks/album-order-reordering-photos-album-ios-12-guide/
It’s important to note that this only works for custom photo albums you’ve created yourself – default albums like “All Photos” and “Favorites” are arranged chronologically and can’t be rearranged this way.
then it's impossible to change the order of “All Photos” and “Favorites” manually - on API level should also be limited.

How to access all the albums and then by clicking the album all the photos should open

I want to show the image selecting option like whatsapp , first fetch list of all the album and then by clicking on that album all the photo should come and being able to keep track of all photo selected by user . i.e Multiple photo selection.enter image description here
I have attached the image to show the requirement.
Please help me.
Thanks in advance
You have to use asset library for it,
Here are some libraries you could use:
1. LimPicker (Similar to WhatsApp's image picker)
2. Fusuma(Instagram like image selector)
3. YangMingShan(Yahoo like image selector)

iOS, How to know whether a photo is a screenshot taken by user? How to delete photos in Photos?

In AppStore(China), an App called Tencent Mobile Manager released a series of functions related to photos, including detecting whether a photo is a screenshot taken by user, deleting photos.
I got screenshots of this app to demonstrate my question here (I added English texts myself for you since the app only shows Chinese):
This app knows what photos are screenshots and what not
When you tap Delete Button at the bottom, it shows:
Asking permission from user to delete photos
As far as I know, Photo APIs (AssetsLibrary, PHPhotoLibrary) in iOS don't give an absolute path of a photo, and iOS SandBox doesn't allow apps to delete user's assets as well, which makes deleting users photos almost impossible. All photos saved in iOS device follows the same naming system: "IMG_001.jpg", which makes it impossible to detect whether a photo is a screenshot from their names.
But apparently, this app implemented both functions. Does anyone have any ideas about this?
Thanks!
You can check using PHAsset's mediaSubtypes property.
let types = phAsset.mediaSubtypes /// phAsset is a PHAsset
let isScreenshot = types.contains(.photoScreenshot) /// true if is screenshot
For screenshot, its UTI is always a "public.png" and same size as screen (be sure you have multiply [UIScreen scale] on screen bounds width and height), just need to check these 2 metadata, you can easily identify screenshot.
Hope this will helps you

Unable to show contact image in shortcut items

We develop an app with some features in iPhone 6s.
I faced some issue when showing the contact image in the shortcut item. I am able to show the dummy image, but I am unable to dynamically fetch the contact image and show in the shortcut items.
My images are in documents directory. I need to show in shortcut item.
UIApplicationShortcutIcon iconWithTemplateImageName: --------]
I tried this:
UIApplicationShortcutIcon * photoIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:SaveImage.png];
I can show a direct local image, but I cannot show the image from addressbook.
Any recommendations are welcome.
This question is confusing. You say your images are "in the documents directory", but you want to display images from the address book.
What I recommend doing is getting the contact you want from the CNContactStore (a CNContact has an image attribute named imageData) and then pass it to UIApplicationShortcutIcon which has an init method that takes a CNContact as a parameter (which means it would actually use that image).

Take photo and store in custom album in Xamarin.iOS

I want to take a photo and save them within a custom album on a iPad.
I tried a lot of things but ended always with wrong image orientation.
My current procedure is:
Take photo with Xamarin.Media and safe image somewhere in my app path
Create custom album if it's not existing
Load image from temporary path and save to the album
Add the image (asset) additionally to the custom album created in 2.
The workflow above is fully working except of saving the correct orientation. After loading an image with library.AssetForUrl() the containing orientation is every time up. Also after converting from asset -> CGImage -> UImage (uiImage.Orientation).
In step 3 I tried to set the orientation the the appropriate one with
var image = new UIImage(tempImage.CGImage, 1.0f, UIImageOrientation.MyOrientation)
and also with the save command
library.WriteImageToSavedPhotosAlbum(image.CGImage, myOrientation, SaveCompletionBlock)
But the orientation is still ignored. I checked this by opening the Album application as well as loading the file in my self written gallery app.
I want to avoid the use of the iOS picker to take photos. This will produce a mess of code!
Or is there any third party library which allows to take photos and store them in a custom album? Which takes care of all the metadata information? It doesn't matter if it's written in objective-c or c#. I will create bindings for it. But it's awful to work with the camera and albums in iOS.
There are tons of hand-made UIImagePickerController alternatives. Some of them:
https://github.com/w5mith/WSAssetPickerController
https://github.com/chute/photo-picker-plus-ios
https://github.com/B-Sides/ELCImagePickerController

Resources