iOS Question Open website error

thestar19

Member
Licensed User
Longtime User
Hey

So I'm trying to open a website in Webview.

If I use the code that you see below, The website never finishes loading, probably because of the way EncodeUrl works.
the problem is that if I parse the url directly I get an Webkit error, se more below.

How do I open the website without getting an error?

Code:


The code that I am currently working with:
B4X:
Dim test As StringUtils
Dim url As String
Log("the url not_coded" & "http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550/sv-se&type=1&id={" & main_map_saved.Get("the_class_code") & "}&period=&week=" & week_number_with_days & "&mode=0&printer=0&Colors=32&head=0&clock=0&foot=0&day=" & which_day_code_to_use & "&width=" & days_use_this_width_when_downloading & "&height=" & use_this_height_when_downloading & "&maxwidth=" & days_use_this_width_when_downloading  & "&maxheight=" & use_this_height_when_downloading)
url = test.EncodeUrl("http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550/sv-se&type=1&id={" & main_map_saved.Get("the_class_code") & "}&period=&week=" & week_number_with_days & "&mode=0&printer=0&Colors=32&head=0&clock=0&foot=0&day=" & which_day_code_to_use & "&width=" & days_use_this_width_when_downloading & "&height=" & use_this_height_when_downloading & "&maxwidth=" & days_use_this_width_when_downloading  & "&maxheight=" & use_this_height_when_downloading,"ISO-8859-1")
download_webview.LoadUrl(url)
Log("the url encoded: " & url)

The logs that I get when I use the code above:
B4X:
Application_Start
Application_Active
the url not_codedhttp://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550/sv-se&type=1&id={877B6E23-FA02-44CC-9967-12A26CCD6FA3}&period=&week=1&mode=0&printer=0&Colors=32&head=0&clock=0&foot=0&day=8&width=320&height=480&maxwidth=320&maxheight=480
the url encoded: http%3A%2F%2Fwww.novasoftware.se%2FImgGen%2Fschedulegenerator.aspx%3Fformat%3Dpng%26schoolid%3D52550%2Fsv-se%26type%3D1%26id%3D%7B877B6E23-FA02-44CC-9967-12A26CCD6FA3%7D%26period%3D%26week%3D1%26mode%3D0%26printer%3D0%26Colors%3D32%26head%3D0%26clock%3D0%26foot%3D0%26day%3D8%26width%3D320%26height%3D480%26maxwidth%3D320%26maxheight%3D480

The error I get if I try to use the webadress directly:
B4X:
*** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]

The url it uses when trying to open the website directly:
B4X:
the url not_coded: http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550/sv-se&type=1&id={877B6E23-FA02-44CC-9967-12A26CCD6FA3}&period=&week=1&mode=0&printer=0&Colors=32&head=0&clock=0&foot=0&day=8&width=320&height=480&maxwidth=320&maxheight=480


Anyone?
 

JanPRO

Well-Known Member
Licensed User
Longtime User
This should work:

B4X:
download_webview.LoadUrl("http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550%2Fsv-se&type=1&id=%7B" & main_map_saved.Get("the_class_code") & "%7D&period=&week=" & week_number_with_days &"&mode=0&printer=0&Colors=32&head=0&clock=0&foot=0&day=" & which_day_code_to_use & "&width=" & days_use_this_width_when_downloading & "&height=" & use_this_height_when_downloading & "&maxwidth=" & days_use_this_width_when_downloading & "&maxheight=" & use_this_height_when_downloading)

But when you only want to load an image then I recommend you to do it like this:

B4X:
Sub LoadImage
Dim HJ As HttpJob
HJ.Initialize("LoadImage",Me)
HJ.Download("http://www.novasoftware.se/ImgGen/schedulegenerator.aspx?format=png&schoolid=52550%2Fsv-se&type=1&id=%7B" & main_map_saved.Get("the_class_code") & "%7D&period=&week=" & week_number_with_days &"&mode=0&printer=0&Colors=32&head=0&clock=0&foot=0&day=" & which_day_code_to_use & "&width=" & days_use_this_width_when_downloading & "&height=" & use_this_height_when_downloading & "&maxwidth=" & days_use_this_width_when_downloading & "&maxheight=" & use_this_height_when_downloading)                                  
End Sub

Sub JobDone (Job As HttpJob)
  If Job.Success = True Then
  Select Job.JobName
  Case "LoadImage"
  ImageView1.Bitmap = Job.GetBitmap 'Use an ImageView and not a WebView to show images
  End Select
  Else
  Log("Error: " & Job.ErrorMessage)
  End If
  Job.Release
End Sub

See: https://www.b4x.com/android/forum/threads/class-httputils2.46565/
 
Upvote 0
Top