iOS Question DocumentPicker question

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all

I created a small project to play with the Document Picker - it allows user to select a pdf that is already on his phone and then it copy this file into the app document folder so I can later send it to my server. So far ot works. As an example I used this project TextEditor.

My question is - do I need to add these PListExtra attributes?
B4X:
    #PlistExtra:<key>CFBundleDocumentTypes</key>
    #PlistExtra:<array><dict><key>CFBundleTypeIconFiles</key><array/>
    #PlistExtra: <key>CFBundleTypeName</key><string>Text File</string>
    #PlistExtra:<key>LSHandlerRank</key><string>Alternate</string>
    #PlistExtra:<key>LSItemContentTypes</key><array>
    #PlistExtra:<string>public.text</string>
    #PlistExtra:</array></dict></array>

I attached my code here.

And here is my code

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: DocumentPicker
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 11
    #ProvisionFile: EVVProfile.mobileprovision
    
    #PlistExtra:<key>CFBundleDocumentTypes</key>
    #PlistExtra:<array><dict><key>CFBundleTypeIconFiles</key><array/>
    #PlistExtra: <key>CFBundleTypeName</key><string>Text File</string>
    #PlistExtra:<key>LSHandlerRank</key><string>Alternate</string>
    #PlistExtra:<key>LSItemContentTypes</key><array>
    #PlistExtra:<string>public.text</string>
    #PlistExtra:</array></dict></array>
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private Button1 As Button
    Type LoadResult (Success As Boolean, Dir As String, FileName As String, RealName As String, Size As Long, Modified As Long, MimeType As String)
    
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
End Sub

Sub Button1_Click

    Try
        Dim DocumentPicker As DocumentPickerViewController
        
        DocumentPicker.InitializeImport("picker", Array("public.content"))
        DocumentPicker.Show(Page1, Button1)
        Wait For Picker_Complete (Success As Boolean, URLs As List)
        If Success Then           
            CopyMe(URLs.Get(0))
        End If
    Catch
        Log(LastException)
    End Try
    
End Sub

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


private Sub CopyMe(url As String)
    Try
        
        Dim FE,FE1 As Boolean
        Dim FName As String
        FE=File.Exists(url,"")
        
        If FE Then
            FName=url.SubString(url.LastIndexOf("/") + 1)
            
            File.Copy(url,"",File.DirDocuments,FName)
            
            FE1=File.Exists(File.DirDocuments,FName)
            
            Log("FE1=" & FE1)
            
        End If
        
    Catch
        Log(LastException)
        
    End Try
End Sub

Thank you.
 

Attachments

  • DocumentPicker.zip
    2.6 KB · Views: 91

Alex_197

Well-Known Member
Licensed User
Longtime User
If I want to select a PDF file do I need to set attributes like this?

B4X:
    #PlistExtra:<key>CFBundleDocumentTypes</key>
    #PlistExtra:<array><dict><key>CFBundleTypeIconFiles</key><array/>
    #PlistExtra: <key>CFBundleTypeName</key><string>PDF File</string>
    #PlistExtra:<key>LSHandlerRank</key><string>Alternate</string>
    #PlistExtra:<key>LSItemContentTypes</key><array>
    #PlistExtra:<string>public.content</string>
    #PlistExtra:</array></dict></array>

Thank you
 
Upvote 0
Top