Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/NSURLConnection test
Required plugins for this example: MBS MacBase Plugin, MBS Images Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSURLConnection test
This example is the version from Mon, 14th Oct 2012.
Project "NSURLConnection test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control iURL Inherits TextField
ControlInstance iURL Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StartButton Inherits PushButton
ControlInstance StartButton Inherits PushButton
EventHandler Sub Action()
dim request as new NSURLRequestMBS(iURL.Text)
dim error as NSErrorMBS
dim response as NSURLResponseMBS
dim d as MemoryBlock = NSURLConnectionMBS.sendSynchronousRequest(request, response, error)
if d<>Nil then
dim pic as Picture = JPEGStringToPictureMBS(d, true)
canvas1.Backdrop = pic
else
canvas1.Backdrop = nil
end if
if error<>Nil then
MsgBox "Error: "+error.description
end if
End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control StartButton1 Inherits PushButton
ControlInstance StartButton1 Inherits PushButton
EventHandler Sub Action()
dim r as new NSURLRequestMBS(iURL.text)
dim m as new MyNSURLConnectionMBS(r)
m.list = Listbox1
m.start
downloaders.Append m
End EventHandler
End Control
EventHandler Sub Resized()
resize
End EventHandler
EventHandler Sub Resizing()
resize
End EventHandler
Sub resize()
dim w as integer = (Width-20-20-14)/2
listbox1.Width = w
canvas1.Width =W
canvas1.left = w+20+14
End Sub
Property downloaders() As Variant
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyNSURLConnectionMBS Inherits NSURLConnectionMBS
EventHandler Function canAuthenticateAgainstProtectionSpace(protectionSpace as NSURLProtectionSpaceMBS) As boolean
List.AddRow CurrentMethodName
End EventHandler
EventHandler Sub didCancelAuthenticationChallenge(challenge as NSURLAuthenticationChallengeMBS)
List.AddRow CurrentMethodName
End EventHandler
EventHandler Sub didFailWithError(error as NSErrorMBS)
List.AddRow CurrentMethodName
List.AddRow "Error: "+error.localizedDescription
End EventHandler
EventHandler Sub didFinishLoading()
List.AddRow CurrentMethodName
dim d as MemoryBlock = me.data
if d<>Nil then
dim pic as Picture = JPEGStringToPictureMBS(d, true)
window1.canvas1.Backdrop = pic
end if
End EventHandler
EventHandler Sub didReceiveAuthenticationChallenge(challenge as NSURLAuthenticationChallengeMBS)
List.AddRow CurrentMethodName
End EventHandler
EventHandler Sub didReceiveData(newData as Memoryblock)
List.AddRow CurrentMethodName
List.AddRow "length: "+str(newData.Size)
End EventHandler
EventHandler Sub didReceiveResponse(response as NSURLResponseMBS)
List.AddRow CurrentMethodName
List.AddRow "expectedContentLength: "+str(response.expectedContentLength)
List.AddRow "suggestedFilename: "+response.suggestedFilename
List.AddRow "MIMEType: "+response.MIMEType
List.AddRow "statusCode: "+str(response.statusCode)
End EventHandler
EventHandler Sub didSendBodyData(bytesWritten as Int64, totalBytesWritten as Int64, totalBytesExpectedToWrite as Int64)
List.AddRow CurrentMethodName
End EventHandler
EventHandler Function shouldUseCredentialStorage() As boolean
List.AddRow CurrentMethodName
End EventHandler
EventHandler Function willSendRequest(request as NSURLRequestMBS, redirectResponse as NSURLResponseMBS) As NSURLRequestMBS
List.AddRow CurrentMethodName
List.AddRow "URL: "+request.URL
// we don't modify it
Return request
End EventHandler
EventHandler Sub willSendRequestForAuthenticationChallenge(challenge as NSURLAuthenticationChallengeMBS)
List.AddRow CurrentMethodName
End EventHandler
Property list As listbox
End Class
End Project
The items on this page are in the following plugins: MBS MacCocoa Plugin.