Class which provides viewing other files with url. Supported formats:
- iWork documents
- Microsoft Office documents (Office ‘97 and newer)
- Rich Text Format (RTF) documents
- PDF files
- Images
- Text files whose uniform type identifier (UTI) conforms to the public.text type (see Uniform Type Identifiers Reference)
- Comma-separated value (csv) files
iOS 8+
pod 'SQUtils/SQPhotoPicker', :git => 'https://github.com/sequenia/SQUtils.git'#import "SQAttachment.h"@interface Data (SQAttachment) <SQAttachment>
@end- Put this code:
@implementation Data (SQAttachment)- Realize
fileUrl-method which returned link to your file (self.linkin my case)
- (NSURL *) fileUrl {
return [NSURL URLWithString:self.link];
}- Realize
fileName-method which returned name of your file (self.namein my case)
- (NSString *) fileName {
return self.name;
}- Realize setter method for fileUrl-property. Don't ask me how it works. Just copy and paste code to your class :D
- (void) setFileUrl:(NSURL *)url {
_link = url.absoluteString;
}- Import
SQFileViewerclass
#import "SQFileViewer.h"- Set property
@property SQFileViewer *fileViewer;- And realize getter for this
fileViewer. If you will setSQFileViewerDelegatedelegate, you can setting progress of loading independently. ElseSQFileViewerwill show alert with progress label and cancel button.
- (SQFileViewer *) fileViewer {
if (!_fileViewer){
_fileViewer = [SQFileViewer fileViewerWithFileAttachments:array
delegate:nil];
}
return _fileViewer;
}
⚠️ NOTE:arrayis the NSArray ofid<SQAttachment>objects
- Controlling of file downloading progress
- (void) fileDownloadedBy:(CGFloat)progress {
//set progress independently
self.progressView.progress = progress; //for example
} [self.fileViewer openFileAt://index of your file
controller:self
completion:^(UIViewController *fileViewerController, NSError *error) {
if (!error && fileViewerController){
[self presentViewController: fileViewerController
animated: YES
completion: nil];
} else {
if (error.code != kCFURLErrorCancelled){
NSLog(@"error = %@", error.localizedDescription);
}
}
}];Nikolay Kagala
- wolferineaz, tabriz@sequenia.com
- sequenia, sequenia@sequenia.com