Swift - sharing photos to Instagram - ios

Im trying to implement UIActivityViewController to my app, It works correctly. However, I'd like to add Instagram to the options. When searching on the internet, I've seen this reply :
"You're able to use UIActivityViewController to show up Instagram as
long there is just an UIImage inside the activity items. It won't show
up if you add more items like text, url etc. This is a bad limitation
made by Instagram.".
Is there any way, how to add Instagram even with initial text, or should I integrate another UIActivityViewController option and turn off all of the other options (FB, Twitter, mail) to show Instagram option? Maybe through if clauses for text?
Here ist the piece of code
#IBAction func ShareRecipe(_ sender: AnyObject) {
let initialText = "-Check out this app"
let img: UIImage = ImageView.image!
let activityVC = UIActivityViewController(activityItems: [img, initialText], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completion: nil)
}

Related

How do I share an image + text via WhatsApp?

I am trying to share an image + text via WhatsApp.
Here is my code:
let activityViewController = UIActivityViewController(activityItems: [imageNmae, "Share text"], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self
activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop]
activityViewController.completionWithItemsHandler = {(activityType: UIActivity.ActivityType?, completed: Bool, returnedItems:[Any]?, error: Error?) in
self.shareMainView.isHidden = true
}
if let viewController = UIApplication.topMostViewController {
viewController.present(activityViewController, animated: true) {
// self.shareMainView.isHidden = true
}
}
How can I achieve this?
I can see some other apps sharing a URL and it's showing both an image and text. Even Android is able to share. But if execute the above code, I can only share text and not an image.
Share URL of the image along with your text.
WhatsApp will create preview from the link, and make it appear like image + text.
There is no real way of sending image + text on WhatsApp (in Nov 2021)

Swift: how to add App sharing feature with Extension Sheet

I want to add the my app sharing feature in my App. Like The Action Sheet Toggle up with the all the social Media and other app in which i can share my app Url. I try to find the tutorial for that but i can't find the proper tutorial for that. this is what I have Done.
func shareApp (){
let textToShare = "Swift is awesome! Check out this website about it!"
if let myWebsite = NSURL(string: "http://www.google.com/") {
let objectsToShare = [textToShare, myWebsite] as [Any]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityType.airDrop, UIActivityType.addToReadingList]
self.present(activityVC, animated: true, completion: nil)
}
This What i Get.
So just want to show there Some Social Media options There.
All you have done is right, except you have not added the App url of your appstore link. Add that link like https://itunes.apple.com/in/app/more-customers-app/id1280868223?mt=8 and all your media will be appear in list if those application is installed in iphone.
You have got UIActivityViewController presented now, Just add in text like,
func ShareApp()
{
let items:[Any] = ["Marketplace of Building Material for Architects, Interior Designers, Contractors and Home Owners. Find Material for your next project. Download https://itunes.apple.com/in/app/more-customers-app/id1280868223?mt=8"]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
self.present(ac, animated: true)
}

How can i share a url like Safari do in my own app

I want to share a url like what Safari do in my own iOS app, How can i do this?
Use socail framework can share in some specified social plartform, but in my case ,I just want to share url like Safari.
Do you think on UIActivityViewController?
#IBAction func shareTextButton(_ sender: UIButton) {
// image to share
let link = "https://www.google.rs/"
// set up activity view controller
let activityViewController = UIActivityViewController(activityItems: [link], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}

Sharing to social media that install on phone iOS Swift

Is there any specific method to share button that detect all social media apps on your iOS phone ?
example : my phone have whatsapp and twitter installed. so when I pressed share button only whatsapp and twitter came out, not facebook and any other apps not installed on my phone.
In android there's particular intent to use that kind of method. However in iOS I still can't find it.
Note : I need it for Swift 3 programmatically
Any help is very useful, Thank you
You should try this:
#IBAction func shareImageButton(_ sender: UIButton)
{
// image to share
let image = UIImage(named: "Image")
// set up activity view controller
let imageToShare = [ image! ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}

UIActivityViewController WhatsApp back to chats button not working

I am presenting a UIActivityViewController to share a url via WhatsApp.
Everything works fine except that the back button in the share dialog of whats app is not working. Swipe to navigate back is working.
Have a look at the screenshot to see the button I am talking about.
My code to present the activity view controller is:
let url: NSURL = NSURL(string: "http://www.google.com")!
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self.videoPlayerController?.presentViewController(activityViewController, animated: true, completion: nil)
Ok, I found the problem.
Somewhere in my app I configured navigation bar to use a custom back button image in the navigation globally by like this:
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "back_icon")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "back_icon")
After I changed it to be not globally anymore it worked:
self.navigationBar.backIndicatorImage = UIImage(named: "back_icon")
self.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back_icon")
Thank you stack overflow.

Resources