问题
I am developing a Xamarin Forms application with Android and iOS solutions. I am desperately searching for a full example to allow a user to share on Instagrama picture taken from my app.
Anyone can point to some good tutorial/example/github repo/etc. ?
回答1:
You can't directly post to an Instagram API as that is private, but you can Share a photo, with the Instagram app, if the user has that installed on their phone. Which is what I think you are trying to achieve. I don't know of any repo or sample, hence will need to do a bit of work yourself on this.
To do this you can use the Instagram Uri Scheme. For iOS you will need to use the Document Interaction section, in Android, you start a new activity and pass the media through.
You will need to code these natively and use Dependency Injection, to pass it into your Xamarin Forms app. An example on how to start an Activity in Android is as such:
public Task<bool> LaunchApp(string uri)
{
bool result = false;
try
{
var aUri = Android.Net.Uri.Parse(uri.ToString());
var intent = new Intent(Intent.ActionView, aUri);
Xamarin.Forms.Forms.Context.StartActivity(intent);
result = true;
}
catch (ActivityNotFoundException)
{
result = false;
}
return Task.FromResult(result);
}
Modify Instagram's example to suit.
来源:https://stackoverflow.com/questions/45505655/xamarin-forms-share-picture-on-instgram