Here we will show how to quickly integrate Sequencing File selector harnesses into your Swift based application.
We have developed a CocoaPod component to simplify using Swift library in your project. If you are new to CocoaPods, refer to the official guide.
There are several prerequisites in order to complete the integration:
- you need to have a Sequencing account
- you need to have an OAuth2 application secret
- you have valid OAuth2 authentication token
In order to complete integration follow instructions below.
By following steps below you would get following UI
Prepare environment
1) Open existing XCode project or create new one
2) Create Podfile in your project directory:
$ pod init
3) Uncomment following row (as this is Swift pod)
use_frameworks!
4) specify following pod parameters in Podfile
pod 'sequencing-oauth-api-swift', '~> 2.0.2'
5) Install the dependency in your project using terminal
$ pod install
6) Use Xcode workspace instead of the project file
$ open *.xcworkspace
Set up OAuth2 module
Refer to the appropriate guide.
Prepare file selector
1) Create bridging header file. Select File > New > File > Header File > name it as
project-name-Bridging-Header.h
2) add SQOAuthFramework class import in the bridging header file
#import <FileSelector/SQFileSelectorFramework.h>
3) register your bridging header file in the project settings select your project > project target > Build Settings > Objective-C Bridging Header specify path for bridging header file
$(PROJECT_DIR)/project-name-Bridging-Header.h
Use file selector
1) subscribe your class to file selector protocol SQFileSelectorProtocol
2) implement methods from SQFileSelectorProtocol protocol
func selectedGeneticFile(_ file: NSDictionary) -> Void {
}
func errorWhileReceivingGeneticFiles(_ error: Error!) {
}
func closeButtonPressed() -> Void {
}
3) call file selector via showFiles(withTokenProvider: showCloseButton: previouslySelectedFileID: delegate:) method
SQFilesAPI.sharedInstance().showFiles(withTokenProvider: SQOAuth.sharedInstance(),
showCloseButton: true,
previouslySelectedFileID: nil,
delegate: self)
where
- tokenProvider - instance of SQOAuth (could be acquired as SQOAuth.sharedInstance())
- showCloseButton - provide BOOL value to specify if you want to have Close button added
- selectedFileID - provide file ID if you want to specific file be preselected and focused
- delegate - UIViewController instance that implements "SQFileSelectorProtocol" protocol implementation
When user selects any file and clicks on "Continue" button in File Selector UI - selectedGeneticFile method from SQFileSelectorProtocol protocol will be called then. Selected file will be passed on as a parameter. In this method you can handle this selected file
Each file is a NSDictionary object with keys and values format as specified here