Auto attach files
Automatically attach a log file to each ticket, or user's profile photo, or whatever will help you resolve the ticket faster when you receive it. Files you attach automatically are not visible to your users.
Auto-attached files vs. Files uploaded by users
When submitting a ticket from the New ticket screen, your users can also upload their files (images, documents) to tickets. That has nothing to do with these auto-attached files.
Methods
You can programmatically attach files by using any of the methods described below.
Set a custom filename and add data
ShakeFile can be initialized with a filename (String) and data (NSData / Data):
- Objective-C
- Swift
NSString *fileName = ...NSData *fileData = ...SHKShake.onPrepareReportData = ^NSArray<SHKShakeFile *> * _Nonnull {NSMutableArray <SHKShakeFile *> *attachedFiles = NSMutableArray.new;SHKShakeFile *attachedFile = [[SHKShakeFile alloc] initWithName:fileName andData:fileData];[attachedFiles addObject:attachedFile];return attachedFiles;};
let fileName: String = ...let logData: Data = ...Shake.onPrepareReportData = {var attachedFiles = [ShakeFile]()let attachedFile = ShakeFile(name: fileName, data: fileData)attachedFiles.append(attachedFile)return attachedFiles}
Set a custom filename and then attach a file
ShakeFile can also be initialized with a desired filename (String) and a local url (NSURL) to your file:
- Objective-C
- Swift
NSString *fileName = ...NSURL *fileUrl = ...SHKShake.onPrepareReportData = ^NSArray<SHKShakeFile *> * _Nonnull {NSMutableArray <SHKShakeFile *> *attachedFiles = NSMutableArray.new;SHKShakeFile *attachedFile = [[SHKShakeFile alloc] initWithName:fileName andFileURL:fileUrl];[attachedFiles addObject:attachedFile];return attachedFiles;};
let fileName: String = ...let fileUrl: URL = ...Shake.onPrepareReportData = {var attachedFiles = [ShakeFile]()if let attachedFile = ShakeFile(name: fileName, fileUrl: fileUrl) {attachedFiles.append(attachedFile)}return attachedFiles}
Attach a file without the custom filename
Lastly, you can initialize ShakeFile only with a local file url (NSURL). If you initialize it this way, the filename shown on your Shake dashboard will be determined automatically from the passed file's name.
- Objective-C
- Swift
NSURL *fileUrl = ...SHKShake.onPrepareReportData = ^NSArray<SHKShakeFile *> * _Nonnull {NSMutableArray <SHKShakeFile *> *attachedFiles = NSMutableArray.new;SHKShakeFile *attachedFile = [[SHKShakeFile alloc] initWithFileURL:fileUrl];[attachedFiles addObject:attachedFile];return attachedFiles;};
let fileUrl: URL = ...Shake.onPrepareReportData = {var attachedFiles = [ShakeFile]()if let attachedFile = ShakeFile(fileUrl: fileUrl) {attachedFiles.append(attachedFile)}return attachedFiles}