iOS Question Document picker

Claude Brun

Active Member
Licensed User
Longtime User
Hi,
I use documentpicker in one app.
App run fine on my iPhone and my iPad (iOS 12)
App crash on iPad of my son (iPad 2nd gen IOS 9)
Is it normal?

Thank
 

Claude Brun

Active Member
Licensed User
Longtime User
hi,
my code using documentpicker

B4X:
Sub btn_import_Click
'   log("btn_inport")
Dim imp As parse
Dim d, f As String
PlayBeep
inact_bntoutil
DocumentPicker.InitializeImport("picker", Array("public.data"))
DocumentPicker.Show(synthese, button2)
Wait For Picker_Complete (Success As Boolean, URLs As List)
If Success Then
  imp = parse_fic(URLs.Get(0))
  d = imp.dir
  f = imp.nom
  File.Copy(d, f, File.DirDocuments, f)
End If
act_bntoutil
End Sub

variable in Process_Clobal
B4X:
Private DocumentPicker As DocumentPickerViewController
Type parse(nom As String, dir As String)
Private hello, synthese As Page
Private button2 As Button

On the old iPad, app crash when i click on the button without showing documentpicker screen

Thank for your help
 
Last edited:
Upvote 0

Claude Brun

Active Member
Licensed User
Longtime User
log (Button2)
<B4IButtonWrapper: <UIButton: 0x1097adb30; frame = (101.381 101.381; 101.381 101.381); hidden = YES; opaque = NO; layer = <CALayer: 0x282471a40>>>

I can't use BarButton because on my layout Navigation Bar and Navigation Toolbar are disable
 
Upvote 0

Claude Brun

Active Member
Licensed User
Longtime User
Hi,
I Don't know how to create BarButton with designer.
I create BarButton 'br' with this code
B4X:
br.InitializeBitmap(LoadBitmapResize(File.DirAssets, "bbimp.png", 32dip, 32dip, True), "bbimp")
synthese.TopRightButtons = Array(br)

Using BarButton, DocumentPiker work fine on my iPhone but it do not work on my iPad (app do not crash but nothing happens. (for memory DocumentPicker work fine on my iPhone and my iPad with simple button)

log(br) on iPhone
<B4IBarButtonItemWrapper: <UIBarButtonItem: 0x104f2af70> target=0x104f29a30 action=toolbarClick: image=<UIImage: 0x282bc2e60>, {32, 32}>
log(br on iPad)
<B4IBarButtonItemWrapper: <UIBarButtonItem: 0x104c39ae0> target=0x104940cc0 action=toolbarClick: image=<UIImage: 0x280a63aa0>, {32, 32}>
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not sure whether it will help however it is worth a shot:
1. Add the iCloud capability to the app id and download a new provision profile.
2. Add this to your code:
B4X:
    #Entitlement:     <key>com.apple.developer.icloud-services</key><string>*</string><key>com.apple.developer.icloud-container-identifiers</key><array></array>
    #Entitlement: <key>com.apple.developer.icloud-container-development-container-identifiers</key><array></array>
 
Upvote 0

Claude Brun

Active Member
Licensed User
Longtime User
Results after many tests
Using button and initial provision profile :
- Ok on iPhone (IOS 12)
- Ok on iPad (IOS12)
- Crash on iPad (IOS9)

Using BarButton and initial provision Profile
- Ok on iPhone (IOS 12)
- nothing happens iPad (IOS12)
- Crash on iPad (IOS9)

Using button and new provision profile with iCloud capability (I was obliged to create explicit id, not possible to add iCloud capability with wildcard id)
- Ok on iPhone (IOS 12)
- Ok on iPad (IOS12)
- Crash on iPad (IOS9)

however, On old iPad it is possible to import a document into app. Selecting then file on the cloud and open with my app. App open and the file is in dir.document folder.

Thank
 
Last edited:
Upvote 0

Claude Brun

Active Member
Licensed User
Longtime User
Indeed, with Try / Catch I was able to obtain information about the crash
App crash on DocumentPicker.Show and LastException is :
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Object was not initialized (UIDocumentPickerViewController)" UserInfo={NSLocalizedDescription=Object was not initialized (UIDocumentPickerViewController)}>

My variable DocumentPicker is declared on Process Global as :
Private DocumentPicker As DocumentPickerViewController

B4X:
Sub btn_import_Click
'   log("btn_inport")
    Dim imp As parse
    Dim d, f As String
    PlayBeep
    inact_bntoutil
    Try
    DocumentPicker.InitializeImport("picker", Array("public.data"))
    Catch
        Creat_Log("btn_import DP init", LastException)
        hd.toastmessageshow("Erreur : Voir fichier Log",False)
    End Try
    Try
    DocumentPicker.Show(synthese, button2)
    Catch
        Creat_Log("btn_import DP Show", LastException)
        hd.toastmessageshow("Erreur : Voir fichier Log",False)
    End Try
    Try
    Wait For Picker_Complete (Success As Boolean, URLs As List)
    If Success Then
        imp = parse_fic(URLs.Get(0))
        d = imp.dir
        f = imp.nom
        File.Copy(d, f, File.DirDocuments, f)
    End If
    Catch
        Creat_Log("btn_import DP Wait", LastException)
        hd.toastmessageshow("Erreur : Voir fichier Log",False)
    End Try
    act_bntoutil
End Sub

on iPhone or iPad with IOS 12 this sub work fine. App crash only on old Ipad with IOS 9
 
Last edited:
Upvote 0

Claude Brun

Active Member
Licensed User
Longtime User
CFBundleDocumentTypes work on the old iPad

the first error is of course the init.
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?" UserInfo={NSLocalizedDescription=Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?}>

I use an App ID with iCloud capabilities and i create a new provision profile with this ID
The 2 lines #Entitlement have been added
Capture d’écran 2020-01-27 à 23.45.15.png


my iCloud container identifier is same that App ID (with 'iCloud.' at the beegining)

must specify iCloud Container identifier in b4i?
 
Upvote 0

Claude Brun

Active Member
Licensed User
Longtime User
Thank you for your help,
I will manage the import differently on older device.
It is Ok with CFBundleDocument
 
Upvote 0
Top