iOS SDK Samples - Photos and Attachments Operations

Get a List of Attachments
          
          
// record is the object of getRecordDelegate

        $record.getAttachments { ( result ) in
            switch result
            {
            case .success(let attachments, let response) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
              print ( "Throws exception : \(error)" )
            }
        }
 
Get Attachments with params
          
          
var recordParams = ZCRMQuery.getEntityRequestParams
        recordParams.page = 200
        recordParams.perPage = 100
// record is the object of getRecordDelegate
        $record.getAttachments(withParams: recordParams) { ( result ) in
            switch result
            {
            case .success(let attachments, let response) :
             print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
             print ( "Throws exception : \(error)" )
            }
        }
 
Upload Attachment using filePath
          
          
// record is the object of getRecordDelegate
$record.uploadAttachment(filePath : "/Users/priya-8673/Desktop/Screenshot"){ ( result ) in
            switch result
            {
            case .success(let attachments, let response) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
               print ( "Throws exception : \(error)" )
            }
        }
 
Upload attachments with fileName and fileData
          
          
let data = tryData(contentsOf: URL(fileURLWithPath: "/Users/priya-8673/Desktop/Screenshot"))
// record is the object of getRecordDelegate
        $record.uploadAttachment(fileName: "invoice.png", fileData: data) { ( result ) in
            switch result
            {
            case .success(let attachments, let response) :
             print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
              print ( "Throws exception : \(error)" )
            }
        }
 
Upload Attachment using FileRefId and File Path
          
          
// record is the object of getRecordDelegate 
$record.uploadAttachment(fileRefId : "123456543", filePath: "/Users/priya-8673/Desktop/Screenshot", attachmentUploadDelegate: self)
        if let attachment = self.attachment
        {
            print(attachment)
        }
        else
        {
            print("Failed to get the attachment")
        }
 
Upload Attachment with fileRefId, fileName and fileData
          
          
let data = tryData(contentsOf: URL(fileURLWithPath: "photos/RelatedAttachment"))
// record is the object of getRecordDelegate
        $record.uploadAttachment(fileRefId : "34567656", fileName: "invoice.png", fileData: data, attachmentUploadDelegate: self)

        if let attachment = attachment
        {
            print(attachment)
        }
        else
        {
            print("Failed to get the attachment id")
        }
 
Download an Attachment using completion
          
          
// record is the object of getRecordDelegate
   $record.downloadAttachment(id: 3456787654567) { ( result ) in
            switch result
            {
            case .success(let response) :
             print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
             print ( "Throws exception : \(error)" )
        }
Download an Attachment using delegate
          
          
// record is the object of getRecordDelegate
        try $record.downloadAttachment(id: 1234565434567, fileDownloadDelegate: self)
 
Delete an Attachment
          
          
// record is the object of getRecordDelegate
        $record.deleteAttachment(id: 345xxx456){ ( delResult ) in
            switch delResult
            {
            case .success(let response) :
               print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
               print ( "Throws exception : \(error)" )
            }
            
        }
 
Upload photo using completion with filePath
          
          
// record is the object of getRecordDelegate
        $record.uploadPhoto(filePath: "/Users/priya-8673/Desktop/Screenshot") { ( result ) in
            switch result
            {
            case .success(let response) :
                print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
                print ( "Throws exception : \(error)" )
            }
        }
 
Upload photos with completion using fileName and fileData
          
          
// record is the object of getRecordDelegate
let filePath = testBundle.path( forResource : "photos/testVoiceNotes", ofType : "png", inDirectory: "resources" )
        let data = try! Data(contentsOf: URL(fileURLWithPath: filePath!))
        $record.uploadPhoto(fileName: "invoice", fileData: data) { ( result ) in
            switch result
            {
            case .success(let response) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
              print ( "Throws exception : \(error)" )
            }
        }
 
Upload photo using delegate with filePath
          
          
// record is the object of getRecordDelegate
$record.uploadPhoto(fileRefId : "Photo With Path Progress", filePath: "/Users/boyle-123/Desktop/Screenshot", fileUploadDelegate: self)
 
Upload photos with delegate using fileName and fileData
          
          
// record is the object of getRecordDelegate
let filePath = testBundle.path( forResource : "photos/testVoiceNotes", ofType : "png", inDirectory: "resources" )
let data = try! Data(contentsOf: URL(fileURLWithPath: filePath!))
$record.uploadPhoto(fileRefId : "Photo With Data Progress", fileName: "invoice", fileData: data, fileUploadDelegate: self)
 
Delete a Photo
          
          
// record is the object of getRecordDelegate
        $record.deletePhoto { ( result ) in
            switch result
            {
            case .success(let response) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
              print ( "Throws exception : \(error)" )
            }
        }
 
Download a Photo using delegate
          
          
// record is the object of getRecordDelegate
 $record.downloadPhoto( fileDownloadDelegate: self )
 
Download a Photo using completion
          
          
// record is the object of getRecordDelegate
        $record.downloadPhoto { ( result ) in
            switch result
            {
            case .success(let response) :
              print ("ResponseJSON : \( response.responseJSON )")
            case .failure(let error) :
              print ( "Throws exception : \(error)" )
            }
        }