iOS Question Using URL schemes to share photos to Instagram

JackKirk

Well-Known Member
Licensed User
Longtime User
I have been playing around with sharing photos from my app to Instagram.

I have worked out how to do it with DocumentInteraction, with code of the form:
B4X:
Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private di As DocumentInteraction
End Sub

Private Sub Application_Start (Nav As NavigationController)

    NavControl = Nav

    Page1.Initialize("Page1")
    Page1.RootPanel.Color = Colors.Green
    NavControl.ShowPage(Page1)
    di.Initialize("di", File.DirAssets, "test.igo")
    di.UTI = "com.instagram.exclusivegram"

End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)

End Sub

Private Sub Application_Background

End Sub

Sub Page1_Click
    di.OpenFile(Page1.RootPanel)
End Sub
This results in a decidedly messy user interaction - you get a menu asking for the app to share with even if Instagram is the only candidate.

According to this hit:

http://blog.horizon.camera/post/102273431070/video-share-objc-ios-instagram

there are some undocumented URL schemes that allow you to directly share content.

I have experimented with URL schemes in a slightly different context and got it working but I cannot for the life of me work out how to use (as expressed in the above hit):

instagram://library?AssetPath=[URL ENCODED STRING OF PHOTO LIBRARY ASSET URL]

in B4i, so that I can share a jpg from DirAssets.

Any suggestions appreciated...
 

JackKirk

Well-Known Member
Licensed User
Longtime User
This will only work with photos added to the camera roll.

Erel, are you referring to the DocumentInteraction or URL schemes part of the first post?

If you are referring to the URL schemes part, what would be the code I would use instead of [URL ENCODED STRING OF PHOTO LIBRARY ASSET URL]?

Thanks...
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
However you will need to add any image you like to the camera photo roll first.

I assume I could do this with Nareck Adonts ALAssets library:

https://www.b4x.com/android/forum/threads/alassets-wraps-the-native-alassets-framework-photos.65231/

While looking through that code I stumbled across this:
B4X:
-(void)SaveVideo: (NSString*)path
{
//[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
NSURL *videoFilePath = [NSURL URLWithString:path];
NSString *caption = @"Some Preloaded Caption";
ALAssetsLibrary *library = [self defaultAssetsLibrary] ;
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:path] completionBlock:^(NSURL *assetURL, NSError *error) {
    NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",[[assetURL absoluteString] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[caption stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
   // NSLog([instagramURL absoluteString]);
    //if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    //    [[UIApplication sharedApplication] openURL:instagramURL];
    //}
    [self.bi raiseEvent:nil event:@"video_saved:" params:@[([assetURL absoluteString])]];
}];

}
Which does not appear to be used in his library but looks tantalizing like what I am after (note the reference to instagram midstream) could I get some help B4i'ing it?
 
Upvote 0
Top