iOS Question Error in saving file in simulator

BerlinCoder

Member
Licensed User
Hi guys,
I am trying to choose a document [ such as an image from gallery] and upload it to my web service. I use the following code to save a chosen image from galley into a file and then upload it to my server, but I face with an error. This error is there because I am using mac builder and simulator?

B4X:
Sub InitCamera
    cam.Initialize("cam", pageCamera1)
End Sub

Sub btnChoosePicture_Click
    InitCamera
    cam.SelectFromSavedPhotos(Sender, cam.TYPE_ALL)
End Sub

Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
    Dim p As Phone
    If Success Then
        If Image.IsInitialized Then
            vv.View.Visible = False
            ImageView1.Bitmap = Image
            p.AddImageToAlbum(Image)
           
            Try
            Dim Success As Boolean
            Success = SaveImage(ImageView1, PublicCodes.CustomerID & "_" & "English_Attachment.jpg",File.DirTemp,100)
           
            Catch
                Log(LastException)
                Return True
            End Try
            PublicCodes.attachedDocFlag=True
'            If Success <> True Then
'                Log(LastException)
'            End If
           
        Else
            vv.View.Visible = True
            vv.LoadVideo(VideoPath, "")
            Log(p.AddVideoToAlbum(VideoPath, ""))
            timer1.Enabled = True
        End If
    End If
End Sub

Sub SaveImage (Image As Bitmap, Filename As String, Dir As String, Quality As Int) As Boolean
    Dim Result As Boolean= True
    Dim out As OutputStream = File.OpenOutput(Dir, Filename, False)
    Dim data() As Byte = GetByteFromBitmap(Image, Quality)
    Try
        out.WriteBytes(data, 0, data.Length)
    Catch
        Result = False
    End Try
    out.Close
    Return Result
   
End Sub


Sub GetByteFromBitmap(img As Bitmap, Quality As Int) As Byte()
    Dim out As OutputStream
    Dim data() As Byte
    out.InitializeToBytesArray(1)
    img.WriteToStream(out,Quality,"JPEG")
    data = out.ToBytesArray
    out.Close
    Return data
End Sub

B4X:
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 " Expected: UIImage, object type: UIImageView" UserInfo={NSLocalizedDescription= Expected: UIImage, object type: UIImageView}>
 
Top