iOS Tutorial Open local files with external apps

Erel

Administrator
Staff member
Licensed User
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: http://www.b4x.com/android/forum/threads/open-external-files-with-your-app.50525/#content).



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
 

falbertini

Member
Licensed User
Thanks, that's what I need..

I tried it now, for example with a xls file but worked only once... In my Iphone 4S I installed Microsoft Excel and in the dialog I choosed "Open in Excel".. One time worked, other times closed my app and returned to the main Iphone screen.
Tried with other extensions (for example .doc .docx with Word) but closes my app and returned to the main Iphone screen
Is there a way to catch if the file was opened correctly ?

The code I use is this:
B4X:
Dim di As DocumentInteraction
di.Initialize("di", folderName, fileName)
di.OpenFile(f.RootPanel)
 

cengolo

Member
Licensed User
this does not open the MOV file in default system player. where am i wrong?

di.Initialize("di", File.DirAssets, "buk1.mov")
di.UTI="com.apple.quicktime-movie (kUTTypeQuickTimeMovie)"
di.OpenFile(Page1.RootPanel)
 

cengolo

Member
Licensed User
what i want is not to play the video inside the app (since the app is only a webview actually) but to open the video in the system player externally. so when the user watches the video and click finish, i return to the app where it stayed. does videoview do that?
 

n3t

Member
Licensed User
If no app is register for a certain file type DI will not start and no event is raised.
How we can detect this issue?

thanks
 

n3t

Member
Licensed User
I get a conversion error on value returned by di.OpenFile:

Application_Start
Application_Active
An error occurred:
(Line: 41) 41
java.lang.RuntimeException: Cannot parse: as boolean

with code
Dim res As Boolean = di.OpenFile(Panel1)
If res = False Then
hd.ToastMessageShow("No app present!", "")
End If

or

If di.OpenFile(Panel1) = False Then
hd.ToastMessageShow("No app present!", "")
End If
 

tucano2000

Active Member
Licensed User
With Document Iteration is possible to directly open an application without showing a list and send parameters ?
 
Top