iOS Tutorial Open local files with external apps

iPhone library v1.40 includes a new object type named DocumentInteraction.

With this controller you can allow the user to open a local file with an external app (this is the other side of this tutorial: https://www.b4x.com/android/forum/threads/open-external-files-with-your-app.50525/#content).

SS-2015-03-18_09.27.24.png


Using DocumentInteraction is pretty simple. You initialize it with the file that you want to open and then call DocumentInteraction.OpenFile.

You can optionally set the file type with the UTI property. The system types are listed here: https://developer.apple.com/library...fiers.html#//apple_ref/doc/uid/TP40009259-SW1

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, "Workbook.xls") '<--- open a file from the assets folder
End Sub

Sub Page1_Click
   di.OpenFile(Page1.RootPanel)
End Sub

Sub di_Closed
   Log("Dialog closed")
End Sub

Sub di_SendingFile
   Log("Opening file")
End Sub
 

n3t

Member
Licensed User
Longtime User
@n3t have you copied the xml file to internal libraries folder?

@tucano2000 in most cases it works properly without setting the type. Have you tried it?
Yes the lib is ok.
Tested on iPhone and iPad.
Same problem. Seems that the returned value is not a Boolean (may be a Int?)
 

n3t

Member
Licensed User
Longtime User
V2.0 beta will be soon released. Please try it again with the beta version. If it doesn't work then you should post the code.
Tested with last beta.
It's OK.

thanks
 
Last edited:

mrossen

Active Member
Licensed User
Longtime User
Hi,

Is it possible to change the language in the window. The text for the apps and "Cancel" is always in English.

I would like to change this to my phones default language. (Danish)

Mogens
 

mrossen

Active Member
Licensed User
Longtime User
I haven't changes anything in settings since installation of ios9.

Anything else on the iPhone is on Danish.

When I look in settings/Language & Area it says Danish

Mogens
 

JackKirk

Well-Known Member
Licensed User
Longtime User
I have semi-successfully got DocumentInteraction working in my app.

I say "semi" because I want to share jpgs to the same range of apps as you can from the photos app.

For example, sharing from the photos app I can share to Messages(SMS) and Mail(email) but I can not share to these from my app.

I've googled up on UTIs and tried all that seem even remotely relevant - all to no avail.

Anyone have any insight?
 

JackKirk

Well-Known Member
Licensed User
Longtime User

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel, you can stop worrying again;)

The solution is so stupidly simple - I'm not sure what this says about me.

B4X:
                    UI_activityviewcontroller.Initialize("Event_UI_activityviewcontroller", Array(wrk_bmp))
                    UI_activityviewcontroller.Show(Showlist_page, Showlist_page.RootPanel)

NOT:
B4X:
                    UI_activityviewcontroller.Initialize("Event_UI_activityviewcontroller", Array("text message", wrk_bmp))
                    UI_activityviewcontroller.Show(Showlist_page, Showlist_page.RootPanel)

Instagram only accepts images (apparently) so if you dispense with the "text message", I get the identical popup as when I share an image from the Photos app.

Happy days...
 

tcgoh

Active Member
Licensed User
Longtime User
Hi,

Can I open an external CSV file stored in dropbox with my own APP created by B4i using this lib?

Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
Hello everyone,

I put this code inside B4XPages and I get this error
B4X:
Sub Class_Globals
    Private di As DocumentInteraction
End Sub

Public Sub VievFile(Path As String, FileName As String)
        di.Initialize("di", Path, FileName)
        di.OpenFile(B4XPages.GetNativeParent(B4XPages.MainPage).RootPanel)
End Sub

Warning: Attempt to present <_UIDICActivityViewController: 0x10182bc00> on Page (vc): Azienda Digitale whose view is not in the window hierarchy!
 

Star-Dust

Expert
Licensed User
Longtime User
I honestly don't know exactly how to answer this question. It is a B4XPages App that works in the foreground. When I call this code I am in a B4XPages page, I guess I should consider the Main Page visible because I see the B4XPage
 
Top