Up to iOS 12.4 the implementation of photo sharing to Instagram feed (following the documentation) worked properly, but since iOS 13 it does not work anymore.
With current implementation - UIDocumentInteractionController
's UTI is set to "com.instagram.exclusivegram"
and file extension to .igo
- there's no Instagram share option visible at all. When I change file extension to .ig
I can see Instagram share option among suggestions. This way sharing to feed works but that's not the expected Instagram-only solution.
Setting UTI to "com.instagram.photo"
does not change anything.
The expected behavior is to see view visible below when I hit "share" button, without additional steps. Could that be Instagram's bug or is there some other way of implementing it for iOS 13?
How Do I Allow Instagram To Access All My Photos? Open App Info of the Instagram app. Find the App Permissions option and check all the allowed permissions. If you don't see Camera and Files and Media under this list, allow these permissions for the app.
Instagram is no longer a photo sharing app, according to Adam Mosseri, the head of Instagram. In a video posted to his Instagram and Twitter accounts, Mosseri said the company is looking to lean into entertainment and video after seeing the success of competitors like TikTok and YouTube.
Always try restarting your phone or tablet first if you're having trouble with Instagram. If restarting your device doesn't help, please try using Instagram both on Wi-Fi and on your mobile data connection to see if the problem is because of a weak Wi-Fi or mobile data connection.
you should add your image to photo library then share the image from it directly to instagram
first of all don’t forget to add NSPhotoLibraryAddUsageDescription and instagram scheme to your info.plist:
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) wants to save pictures to your library</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>instagram</string>
</array>
Works correctrly for 12.4 and 13 iOS
import UIKit
import Photos
class TestViewController: UIViewController, UIDocumentInteractionControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
postImageToInstagram(UIImage(named: "bigImage")!)
}
func postImageToInstagram(_ image: UIImage) {
// Check if we have instagarm app
if UIApplication.shared.canOpenURL(URL(string: "instagram://app")!) {
// Requesting authorization to photo library in order to save image there
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
} else { print("wrong status \(status)") }
}
} else { print("Please install the Instagram application") }
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error = error {
print(error)
return
}
let fetchOptions = PHFetchOptions()
// add sorting to take correct element from fetchResult
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
fetchOptions.fetchLimit = 1
// taking our image local Identifier in photo library to share it
let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions)
if let lastAsset = fetchResult.firstObject {
let url = URL(string: "instagram://library?LocalIdentifier=\(lastAsset.localIdentifier)")!
if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) }
else { print("Please install the Instagram application") }
}
}
}
Result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With