iOS Question Can't Initialize BarcodeScanner

shirlun

Active Member
Licensed User
Longtime User
B4I v3.01

My code seems no mistake, but BarcodeScanner Crashes in Initialize method.

B4X:
'Code module
#Region  Project Attributes 
    #ApplicationLabel: B4i Example
    #Version: 1.0.0 
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #MinVersion: 7
#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
   
    Dim Scan As BarcodeScanner
    Dim hScanPanel As Panel
   
End Sub

Private Sub Application_Start (Nav As NavigationController)

    Page1.Initialize("page1")   
    Nav.ShowPage(Page1)
       
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
    'Log("12{34567".LastIndexOf2("{", 6))
    'Log("12{34567".LastIndexOf2("{", 7))

    ScanTest

End Sub

Sub ScanTest
   
    Dim w, h As Int
    Dim b As Label
    Dim p As Panel
   
    hScanPanel.Initialize("hScanPanel")

Log(1)   'some time can show 1
    Scan.Initialize("scan", hScanPanel)
   
Log(2)    'any time can't show 2
    Scan.TorchMode = Scan.TORCH_AUTO
Log(3)   

    w = Page1.RootPanel.Width
    h = Page1.RootPanel.Height
   
    p.Initialize("")
    p.SetBorder(2, Colors.Cyan, 10)
   
    hScanPanel.AddView(p, 0, 0, w, h)

    b.Initialize("ScanButton")
    b.text = "Close"
    b.TextColor = Colors.White
   
    p.AddView(b, p.Width - 60, p.Height - 60, 50, 50)

    Page1.RootPanel.AddView(hScanPanel, 0, 0, w, h)
   
End Sub

Sub ScanButton_Click

    Scan.Stop
    hScanPanel.RemoveViewFromParent

End Sub

Sub hScanPanel_Resize(w As Float, h As Float)

Log("panel_resize")   
    Scan.Resize
   
End Sub

Sub Scan_Ready(success As Boolean)

Log("scan_ready")
    If success Then
      Scan.Start
    End If  
   
End Sub

Sub Scan_Detected(codes As List)

    Dim code As BarcodeCode = codes.Get(0)
    Dim s As String = code.Value
   
    Log(s)
         
End Sub
 

shirlun

Active Member
Licensed User
Longtime User
Solved, must add

B4X:
    #PlistExtra:<key>NSCameraUsageDescription</key><string>Read barcodes</string>

My be caused by iOS 10
 
Upvote 0
Top