iOS Question Execute Listview and Detecting Internet Connectivity

Discussion in 'iOS Questions' started by MurphmanL, Apr 5, 2015.

  1. MurphmanL

    MurphmanL Member Licensed User

    Hi all,

    I have been happily porting my B4A app to iOS over the holiday but have run into a few roadblocks. Some of which I have managed to answer myself by digging around the forum, but I do have two questions if I may pitch to the community that I haven't been able to find a solid answer on in order to accelerate my porting process.

    1) My app relies on the ExecuteListView method of DbUtils, which appears to be disabled in the B4i version. Upon un-commenting it and trying to get it going, it seems to fall over as the ListView method in B4i doesn't support the Addsingleline or Addtwoline arguments. Is there any workaround for this as my app depends on being able to generate a list using this method and I am struggling to think of a workaround.

    2) In B4i I used to use a combination of phone get data state and server socket to detect whether the phone has data connectivity. Since phone get data state is now broken, is there an alternative method I can use?

    Many thanks to anyone who is able to offer some input.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code to fill a TableView (add it to DBUtils):
    Code:
    Public Sub ExecuteListView(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, ListView1 As TableView, _
       TwoLines 
    As Boolean)
       ListView1.Clear
       
    Dim Table As List
       Table = ExecuteMemoryTable(
    SQL, Query, StringArgs, Limit)
       
    Dim Cols() As String
       
    For i = 0 To Table.Size - 1
         Cols = Table.Get(i)
         
    Dim tc As TableCell
         
    If TwoLines Then
           tc = ListView1.AddTwoLines(Cols(
    0), Cols(1))
         
    Else
           tc = ListView1.AddSingleLine(Cols(
    0))
         
    End If
         tc.Tag = Cols
       
    Next
    End Sub
    2) You can use ServerSocket.GetMyIp to test for a network ip address. Eventually the best way to make sure that there is a live connection is to send a request and see whether it succeeds or not.
     
  3. MurphmanL

    MurphmanL Member Licensed User

    Hi,

    I have tried incorporating the above DBUtils code and while it does seem to work, no matter how I seem to code it I can't seem to get the users allocations to show while on my B4A app they are showing perfectly :(

    Code:
    Sub RunAllocs
        
    SQL.BeginTransaction

    SQL.ExecNonQuery("DROP TABLE IF EXISTS Allocations")
    SQL.ExecNonQuery("CREATE TABLE Allocations (Date TEXT, UserID INTEGER , Site TEXT, Timeslot TEXT, Info TEXT, Postcode TEXT)")
       

      
    '    Try

        
    Dim lst1 As List
        lst1 = su.LoadCSV(
    File.DirLibrary,"Allocation.csv"",")
        
    For i = 1 To lst1.Size - 1
        
    Dim sColumn() As String
        sColumn = lst1.Get(i)
        
    SQL.ExecNonQuery2("INSERT INTO Allocations (Date,UserID,Site,Timeslot,Info,Postcode) VALUES (?, ?, ?, ?, ?, ?)", sColumn)
        
    Next
        
    SQL.TransactionSuccessful
    '   Catch
       ' Log(LastException.Description)
       ' End Try
       
      
    '  SQL.ExecNonQuery("DELETE FROM Allocations WHERE UserID <> '" & Main.AuditorNo & "'")

        
    Dim CHecktxt As String
        CHecktxt = SearchMe.Text

        
    If Checkbox1.Value = False Then

    DBUtils.ExecuteListView(
    SQL"SELECT Site FROM Allocations WHERE Date ='" & TodayIs & "' AND Site LIKE '%" & CHecktxt & "%'"Null0, Listview1, False)
    Else

    DBUtils.ExecuteListView(
    SQL"SELECT Site FROM Allocations WHERE Site LIKE '%" & CHecktxt & "%'"Null0, Listview1, False)
    End If
        
    SQL.Close

    End Sub
    The result of the above, running after the listview1 table view is initialized, when combined with the ExecuteListView, seems to yield no records into the listview1 tableview. :( If you observe the code above I have even commented out the error trapping and was trying a simple select list statement with no criterion just to get the tableview to populate - all return no records.

    Can anyone see any obvious errors in the above code?

    I am starting to wonder if I am going to manage porting my app to iOS as I have ran into a brick wall with reading/writing to a csv file too... with the absence of textreader/writer I turned to a bytes suggestion I read on the forum and that does not seem to be a particularly reliable solution in place of the android text writer... but that's for another thread!
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You don't need to work with bytes. You should use File.ReadString or File.ReadString2.

    Can you upload your project or a small project that demonstrates this issue?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    There are several missing modules (About and Support and maybe others). Use Export As Zip - Include Shared modules.
     
  6. MurphmanL

    MurphmanL Member Licensed User

    Hi Erel,

    The modules were removed as they contained sensitive information. I have removed the outstanding references to these removed modules in the attached example.

    The key elements that I need assistance with are included, as well as an example allocation file that needs to populate the table view.

    The issues I have are -

    1) When I port the working code from B4a to populate the listview on the "ChooseLoc" activity, with the 'allocations csv' contents, nothing ever shows in the ios table view. I am lost as to why this is the case.
    2) I have no reliable way of populating a csv file with stamped data now that the text reader/writer control is not available. I did a bytes implementation as shown on the "Audit" activity.

    Suggestions to the above two points would be appreciated. If anything is not clear, please let me know.
     

    Attached Files:

  7. narek adonts

    narek adonts Well-Known Member Licensed User

    Why you are not using file.readstring ?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice