Skip to content

Share to Instagram

Stanislav Osipov edited this page Apr 1, 2020 · 1 revision

Starting with the iOS 13 default method that was used by the majority of iOS developers is no longer working.

The new approach is to use a URL scheme to share the image. The issue is that this image has to be added to the user photo library. The code below demonstrates how you can do that with the iOS Native plugin:

using SA.iOS.Photos;
using SA.iOS.UIKit;
...

var myImageToShare = GetMyImage();
ISN_PhotoAlbum.UIImageWriteToSavedPhotosAlbum(sampleRedTexture, (result) =>
{
   if (result.HasError)
   {
       Debug.LogError(result.Error.FullMessage);
       return;
   }

   var fetchOptions = new ISN_PHFetchOptions();
   fetchOptions.SortDescriptor = new ISN_NSSortDescriptor("creationDate", false);
   fetchOptions.FetchLimit = 1;

   var fetchResult = ISN_PHAsset.FetchAssetsWithOptions(fetchOptions);

   var lastAsset = fetchResult.FirstObject;
   var url = "instagram://library?LocalIdentifier=" + lastAsset.LocalIdentifier;

   if (ISN_UIApplication.CanOpenURL(url))
       ISN_UIApplication.OpenURL(url);
   else
       Debug.LogError("Instagram application is not installed!");
});

About

Foundation

AV Foundation

App Tracking Transparency

Game Kit

Store Kit

UI Kit

Social

Replay Kit

Contacts

AVKit

Photos

App Delegate

User Notifications

MediaPlayer

Core Location

AdSupport

EventKit

CloudKit

Authentication Services

XCode

Knowledge Base

Clone this wiki locally