Share full-size image from remote URL - ios

I found this tutorial in order to let my users share images from my app:
https://www.hackingwithswift.com/articles/118/uiactivityviewcontroller-by-example
Here is the relevant code:
let items = [yourImage]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
present(ac, animated: true)
It looks like I need to pass a UIImage in the items array.
In my app, I show a feed of images. In the API call for the feed, each image has a thumbnail URL (smaller size) and a full-size URL. My app displays the thumbnail images in the feed in order to keep my app speedy.
This activity view controller is triggered when the user long-presses one of the images in the feed. The problem is that I want the user to be able to share the full-size image (which isn't loaded into any ImageView in the feed), instead of the thumbnail image.
How can I do this?
I've considered fetching the full-size image on long press by following this tutorial, but this causes issues in that the activity view controller doesn't actually show until the image is fully downloaded.
What else can I do??
As an additional question, would the same apply to if I wanted to let the user share a video (mp4)?

Related

Share image and/or text through Share Menu on iOS (Swift)

I am looking for a way to share both an image (a screenshot generated by the app) and text, with a preference to the image.
When I try to achieve this, I see it only works for Apple's own Messaging app and maybe a few other apps. But I don't see apps like Snapchat, Tiktok and other famous apps show up in the default share menu that's provided by Apple. For other apps, only the text shows up and the image is ignored.
However, when I leave out the text from the UIActivityViewController so it only contains the image to share, all other apps show up and most of them work perfectly with my image.
How can I make my code so that, if supported, it shares BOTH the image and the text and in other cases gives preference to the image instead of the text. I still want all the apps (like Snapchat, Tiktok and other social media apps) to show up to share to it because this only happens when only the image is in the UIActivityViewController.
This is the code to make sharing work in my app.
func shareMenu() {
if var top = scene?.view?.window?.rootViewController {
while let presentedViewController = top.presentedViewController {
top = presentedViewController
}
let screenshotImage = getScreenshot(scene: scene!)
let activityVC = UIActivityViewController(activityItems: [screenshotImage , "The text that's need to be shared."], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = view
top.present(activityVC, animated: true, completion: nil)
}
}

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)

Unable to setup images from JSON?

I'm using Firebase Database & Firebase Storage. I have an iOS Swift app, that allows the user to select multiple images, upload them to Firebase Storage, after the upload, it gets the downloaded URLs and stores them like:
In order to display those images in the app, I have the following xib file:
Where the middle (big) UIImageView is inside of a UIStackView because it could display more than 1 image.
My problem is that I get the URLs from the database, but for some reason I'm not able to display them in the app. I use the framework SDWebImage for caching and displaying images. So far in the app, it worked fine, but not here. I don't get where I'm wrong.
if let photoURLString = post?.photoURLs
{
for photo in photoURLString
{
let photoURL = URL(string: photo)
print(photoURL!)
postImage.sd_setImage(with: photoURL)
//postImagesStackView.addArrangedSubview(postImage)
}
}
post is the model object. I'm using for in to loop through the array of images from the database. When I print each url, I get the actual URL. But it's simple not displayed. I get this. The images are nowhere to be found/displayed:
Try to add aspect ratio for UIImage. Ex: In xib file, set ratio of UIImage to 1.

Updating Tableview with photos in the background

I'm currently hitting an API to get a list of inventory items. Right now I am also downloading all of the photos for all of the items on initial load. What I want to do is load the table view with all of the text (be able to interact with the tableview) and then load the photos in the background and update each row once the photo has been retrieved so that it loads faster. I have all of the URLs of the photos from the API. How would I do this?
I am using Alamofire Image for this purpose. Here is a sample code.
After installing its pod, you can do:
cell.yourImageView.af_setImageWithURL(url, placeholderImage: nil, filter: nil, imageTransition: .CrossDissolve(0.5), runImageTransitionIfCached: false, completion: {response in
// if you have activity indicator you can stop it when images is downloaded
//cell.activityIdicator.stopAnimating()
})
There are many sdk available for lazyloading. You can use SDWebImage for same.
It will automatically load image into your UIImageView as soon as image download.

Swift - force square photo from library and camera

I'm building an app and I need to FORCE the user to upload square pictures (just like Instagram does), however I'd like to avoid programming an interface from scratch as we're short in time.
It is important to note that the USER must CHOOSE which part of the image he/she wants to show, so cropping the image programatically without asking the user is out of the question.
I've managed to get this to work via camera, however via library I can't seem to force the user to use a square image. Here's the code I have:
func presentGallery(){
// from library
picker.allowsEditing = true
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
presentViewController(picker, animated: true, completion: nil)
}
Then on my imagepickercontroller:
var chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
However I don't get the desired result. It would be fine if the "minimum zoom" was to show 100% of the height of the image, or if I could add a white/black background to the top and bottom of the image.
Here's the problem:
Instead of something like this:
My app needs to work starting from iOS7.
You should do some sort of check to make sure that the picture is square if they're picking from their library.
Once you get the image (using imagePickerController didFinishPickingMediaWithInfo), then get the image with [info objectForKey:UIImagePickerControllerOriginalImage];. Once you've done this, perform the check:
if (image.size.height != image.size.width) // Show some alert
What might be an even better solution is creating a view which allows the user to pick any photo, and then choose a square part of the photo to import into your app, like Instagram does.

Resources